Skip to content

Commit aaf9977

Browse files
authored
Merge pull request #2 from rasa04/feature/cents-test-cases-new
new test cases
2 parents 1869540 + ce98e13 commit aaf9977

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

src/AmoCRM/Models/LeadModel.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ public function getPriceWithMinorUnits(): ?float
267267
*/
268268
public function setPrice($price): self
269269
{
270+
if (!is_int($price) && !is_float($price) && !is_null($price)) {
271+
throw new InvalidArgumentException('Lead price must be an integer, float or null.');
272+
}
273+
270274
$this->price = $price;
271275

272276
return $this;

tests/Cases/Price/LeadPriceTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,22 @@ public function testToApiOmitsPriceWhenItWasNotSet(): void
183183
$this->assertSame(['request_id' => '0'], (new LeadModel())->toApi());
184184
}
185185

186+
public function testSetPriceWithStringThrowsException(): void
187+
{
188+
$this->expectException(InvalidArgumentException::class);
189+
$this->expectExceptionMessage('Lead price must be an integer, float or null.');
190+
191+
(new LeadModel())->setPrice('100.0');
192+
}
193+
194+
public function testSetPriceWithArrayThrowsException(): void
195+
{
196+
$this->expectException(InvalidArgumentException::class);
197+
$this->expectExceptionMessage('Lead price must be an integer, float or null.');
198+
199+
(new LeadModel())->setPrice([100]);
200+
}
201+
186202
private function assertPriceState(LeadModel $lead, ?int $legacyPrice, ?float $priceWithMinorUnits): void
187203
{
188204
$this->assertSame($legacyPrice, $lead->getPrice());

0 commit comments

Comments
 (0)