Skip to content

Commit 92b1871

Browse files
authored
tidy up tests (#12)
1 parent 2559f76 commit 92b1871

File tree

5 files changed

+20
-19
lines changed

5 files changed

+20
-19
lines changed

Tests/Validator/FixedLengthDigitPostalCodeValidatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function testIsConstraintValidator()
2323

2424
public function testValidationWithoutLengthThrowsLogicException()
2525
{
26-
$this->setExpectedException('LogicException');
26+
$this->expectException(\LogicException::class);
2727
$value = '12345';
2828
$constraint = new FixedLengthDigitPostalCodeConstraint();
2929
$this->validator->validate($value, $constraint);

Tests/Validator/PostalCodeConstraintTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,31 @@
33
namespace Markup\AddressingBundle\Tests\Validator;
44

55
use Markup\AddressingBundle\Validator\PostalCodeConstraint;
6+
use Symfony\Component\Validator\Constraint;
67

78
/**
89
* A test for a class-based validator for postal codes that applies validation on a per-country basis.
910
*/
1011
class PostalCodeConstraintTest extends \PHPUnit_Framework_TestCase
1112
{
13+
/**
14+
* @var PostalCodeConstraint
15+
*/
16+
private $constraint;
17+
1218
public function setUp()
1319
{
1420
$this->constraint = new PostalCodeConstraint();
1521
}
1622

1723
public function testIsConstraint()
1824
{
19-
$this->assertInstanceOf('Symfony\Component\Validator\Constraint', $this->constraint);
25+
$this->assertInstanceOf(Constraint::class, $this->constraint);
2026
}
2127

2228
public function testIsDeclaredClassLevelConstraint()
2329
{
24-
$this->assertEquals(\Symfony\Component\Validator\Constraint::CLASS_CONSTRAINT, $this->constraint->getTargets());
30+
$this->assertEquals(Constraint::CLASS_CONSTRAINT, $this->constraint->getTargets());
2531
}
2632

2733
public function testValidatedByPostalCodeValidator()

Tests/Validator/PostalCodeValidatorTest.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
namespace Markup\AddressingBundle\Tests\Validator;
44

5+
use Markup\AddressingBundle\Validator\LocalizedPostalCodeValidatorClosureProvider;
56
use Markup\AddressingBundle\Validator\PostalCodeValidator;
7+
use Symfony\Component\Validator\Constraint;
8+
use Symfony\Component\Validator\ConstraintValidatorInterface;
69

710
/**
811
* A test for a postal code validator that can perform localized postal code validation where available.
@@ -11,24 +14,20 @@ class PostalCodeValidatorTest extends \PHPUnit_Framework_TestCase
1114
{
1215
public function setUp()
1316
{
14-
$this->validatorProvider = $this->getMockBuilder('Markup\AddressingBundle\Validator\LocalizedPostalCodeValidatorClosureProvider')
15-
->disableOriginalConstructor()
16-
->getMock();
17+
$this->validatorProvider = $this->createMock(LocalizedPostalCodeValidatorClosureProvider::class);
1718
$this->validator = new PostalCodeValidator($this->validatorProvider);
1819
}
1920

2021
public function testIsValidator()
2122
{
22-
$this->assertInstanceOf('Symfony\Component\Validator\ConstraintValidatorInterface', $this->validator);
23+
$this->assertInstanceOf(ConstraintValidatorInterface::class, $this->validator);
2324
}
2425

2526
public function testPassingNonObjectThrowsInvalidArgumentException()
2627
{
27-
$constraint = $this->getMockBuilder('Symfony\Component\Validator\Constraint')
28-
->disableOriginalConstructor()
29-
->getMock();
28+
$constraint = $this->createMock(Constraint::class);
3029
$value = 'POSTCODE';
31-
$this->setExpectedException('InvalidArgumentException');
30+
$this->expectException(\InvalidArgumentException::class);
3231
$this->validator->validate($value, $constraint);
3332
}
3433
}

Tests/Validator/RegionValidatorTest.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
use Markup\AddressingBundle\Validator\RegionConstraint;
66
use Markup\AddressingBundle\Validator\RegionValidator;
77
use Mockery as m;
8+
use Mockery\Adapter\Phpunit\MockeryTestCase;
89
use Symfony\Component\Validator\ConstraintValidatorInterface;
910
use Symfony\Component\Validator\Context\ExecutionContextInterface;
1011

11-
class RegionValidatorTest extends \PHPUnit_Framework_TestCase
12+
class RegionValidatorTest extends MockeryTestCase
1213
{
1314
protected function setUp()
1415
{
@@ -18,11 +19,6 @@ protected function setUp()
1819
$this->validator->initialize($this->context);
1920
}
2021

21-
protected function tearDown()
22-
{
23-
m::close();
24-
}
25-
2622
public function testIsValidator()
2723
{
2824
$this->assertInstanceOf(ConstraintValidatorInterface::class, $this->validator);
@@ -31,7 +27,7 @@ public function testIsValidator()
3127
public function testThrowInvalidArgumentExceptionWhenInvalid()
3228
{
3329
$invalid = 'not an address';
34-
$this->setExpectedException('InvalidArgumentException');
30+
$this->expectException(\InvalidArgumentException::class);
3531
$this->validator->validate($invalid, new RegionConstraint());
3632
}
3733

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"mockery/mockery": "~0.9.0",
2626
"symfony/console": "~2.7|~3.0"
2727
},
28-
"suggests": {
28+
"suggest": {
2929
"symfony/validator": "~2.7|~3.0"
3030
},
3131
"autoload": {

0 commit comments

Comments
 (0)