Skip to content

Commit

Permalink
Ajuste para permitir informar letras e números no número do endereço
Browse files Browse the repository at this point in the history
  • Loading branch information
jhernandes committed Apr 10, 2024
1 parent 3da02f0 commit 7e8714a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 26 deletions.
28 changes: 12 additions & 16 deletions src/Model/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace Ipag\Sdk\Model;

use Ipag\Sdk\Model\Schema\Mutator;
use Ipag\Sdk\Util\StateUtil;
use Ipag\Sdk\Model\Schema\Schema;
use Ipag\Sdk\Model\Schema\Mutator;
use Ipag\Sdk\Model\Schema\SchemaBuilder;
use Ipag\Sdk\Util\StateUtil;

/**
* Address Class
Expand Down Expand Up @@ -48,7 +48,7 @@ public function street(): Mutator
{
return new Mutator(
null,
fn($value) => strval($value)
fn ($value) => strval($value)
);
}

Expand All @@ -73,17 +73,12 @@ public function setStreet(?string $street): self
$this->set('street', $street);
return $this;
}

public function number(): Mutator
{
return new Mutator(
null,
fn($value, $ctx) =>
is_null($value) ?
$value :
(
is_numeric($value) ? strval($value) :
$ctx->raise('inválido')
)
fn ($value) => strval($value)
);
}

Expand All @@ -108,9 +103,10 @@ public function setNumber(?string $number): self
$this->set('number', $number);
return $this;
}

public function district(): Mutator
{
return new Mutator(null, fn($value) => strval($value));
return new Mutator(null, fn ($value) => strval($value));
}

/**
Expand All @@ -136,7 +132,7 @@ public function setDistrict(?string $district): self
}
public function complement(): Mutator
{
return new Mutator(null, fn($value) => strval($value));
return new Mutator(null, fn ($value) => strval($value));
}

/**
Expand All @@ -162,7 +158,7 @@ public function setComplement(?string $complement): self
}
public function city(): Mutator
{
return new Mutator(null, fn($value) => strval($value));
return new Mutator(null, fn ($value) => strval($value));
}

/**
Expand All @@ -188,7 +184,7 @@ public function setCity(?string $city): self
}
public function state(): Mutator
{
return new Mutator(null, fn($value) => !$value ? null : StateUtil::transformState($value));
return new Mutator(null, fn ($value) => !$value ? null : StateUtil::transformState($value));
}

/**
Expand All @@ -214,7 +210,7 @@ public function setState(?string $state): self
}
public function zipcode(): Mutator
{
return new Mutator(null, fn($value) => strval(preg_replace('/\D/', '', $value)));
return new Mutator(null, fn ($value) => strval(preg_replace('/\D/', '', $value)));
}

/**
Expand All @@ -238,4 +234,4 @@ public function setZipcode(?string $zipcode): self
$this->set('zipcode', $zipcode);
return $this;
}
}
}
15 changes: 5 additions & 10 deletions tests/Model/AddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Ipag\Sdk\Tests\Model;

use Ipag\Sdk\Model\Schema\Exception\MutatorAttributeException;
use PHPUnit\Framework\TestCase;
use Ipag\Sdk\Model\Schema\Exception\MutatorAttributeException;

class AddressTest extends TestCase
{
Expand All @@ -26,7 +26,6 @@ public function testShouldCreateAddressObjectWithConstructorSuccessfully()
$this->assertEquals($address->getCity(), 'São Luís');
$this->assertEquals($address->getState(), 'MA');
$this->assertEquals($address->getZipcode(), '65076020');

}

public function testShouldCreateAddressObjectAndSetTheValuesSuccessfully()
Expand All @@ -47,7 +46,6 @@ public function testShouldCreateAddressObjectAndSetTheValuesSuccessfully()
$this->assertEquals($address->getCity(), 'São Luís');
$this->assertEquals($address->getState(), 'MA');
$this->assertEquals($address->getZipcode(), '65076020');

}

public function testShouldCreateEmptyAddressObjectSuccessfully()
Expand Down Expand Up @@ -91,17 +89,14 @@ public function testCreateAndSetEmptyPropertiesAddressObjectSuccessfully()
$this->assertEmpty($address->getCity());
$this->assertEmpty($address->getState());
$this->assertEmpty($address->getZipcode());

}

public function testShouldThrowAValidationExceptionOnTheAddressNumberProperty()
public function testShouldAcceptAddressNumberPropertyWithLetters()
{
$address = new \Ipag\Sdk\Model\Address();

$this->expectException(MutatorAttributeException::class);

$address->setNumber('abc');
$address->setNumber('BR 163');

$this->assertEquals('BR 163', $address->getNumber());
}

}
}

0 comments on commit 7e8714a

Please sign in to comment.