Skip to content

Commit 2dc9eb7

Browse files
author
Douglas Greenshields
committed
support only symfony 2.7+ (inc 3.x)
1 parent 8a03532 commit 2dc9eb7

File tree

6 files changed

+43
-24
lines changed

6 files changed

+43
-24
lines changed

Command/TestFormattingCommand.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
77
use Symfony\Component\Console\Input\InputInterface;
88
use Symfony\Component\Console\Output\OutputInterface;
9+
use Symfony\Component\Console\Question\Question;
910

1011
/**
1112
* A console command that allows entering an address in order to see how it will be formatted.
@@ -21,16 +22,19 @@ protected function configure()
2122

2223
protected function execute(InputInterface $input, OutputInterface $output)
2324
{
24-
$output->writeln('<info>This command takes address information and formats the resulting address.');
25+
$questionHelper = $this->getHelper('question');
26+
$ask = function (Question $question) use ($input, $output, $questionHelper) {
27+
return $questionHelper->ask($input, $output, $question);
28+
};
2529

26-
$dialog = $this->getHelperSet()->get('dialog');
30+
$output->writeln('<info>This command takes address information and formats the resulting address.');
2731

28-
$country = $dialog->ask($output, 'What is the two letter ISO3166 code for the country? (e.g. \'US\', \'GB\') ');
32+
$country = $ask(new Question('What is the two letter ISO3166 code for the country? (e.g. \'US\', \'GB\') '));
2933

30-
$addressLines = array();
34+
$addressLines = [];
3135
$lineCount = 1;
3236
while ($lineCount <= 8) {
33-
$line = $dialog->ask($output, sprintf('Line %u of the address? (Press Return to complete entering address.) ', $lineCount));
37+
$line = $ask(new Question(sprintf('Line %u of the address? (Press Return to complete entering address.) ', $lineCount)));
3438
if (!empty($line)) {
3539
$addressLines[] = $line;
3640
} else {
@@ -39,11 +43,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
3943
$lineCount++;
4044
}
4145

42-
$locality = $dialog->ask($output, 'What is the town/ city of the address? ');
46+
$locality = $ask(new Question('What is the town/ city of the address? '));
4347

44-
$postalCode = $dialog->ask($output, 'What is the postal code of the address? (Press Return to leave blank.) ');
48+
$postalCode = $ask(new Question('What is the postal code of the address? (Press Return to leave blank.) '));
4549

46-
$region = $dialog->ask($output, 'What is the region (i.e. state, county or province) of the address? (Press Return to leave blank.) ');
50+
$region = $ask(
51+
new Question(
52+
'What is the region (i.e. state, county or province) of the address? (Press Return to leave blank.) '
53+
)
54+
);
4755

4856
$address = new Address(
4957
$country,

Tests/Validator/FixedLengthDigitPostalCodeValidatorTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@
44

55
use Markup\AddressingBundle\Validator\FixedLengthDigitPostalCodeConstraint;
66
use Markup\AddressingBundle\Validator\FixedLengthDigitPostalCodeValidator;
7+
use Symfony\Component\Validator\ConstraintValidator;
8+
use Symfony\Component\Validator\Context\ExecutionContextInterface;
79

810
class FixedLengthDigitPostalCodeValidatorTest extends \PHPUnit_Framework_TestCase
911
{
1012
protected function setUp()
1113
{
1214
$this->validator = new FixedLengthDigitPostalCodeValidator();
13-
$this->context = $this->getMock('Symfony\Component\Validator\ExecutionContextInterface');
15+
$this->context = $this->getMock(ExecutionContextInterface::class);
1416
$this->validator->initialize($this->context);
1517
}
1618

1719
public function testIsConstraintValidator()
1820
{
19-
$this->assertInstanceOf('Symfony\Component\Validator\ConstraintValidator', $this->validator);
21+
$this->assertInstanceOf(ConstraintValidator::class, $this->validator);
2022
}
2123

2224
public function testValidationWithoutLengthThrowsLogicException()

Tests/Validator/MultipleRegexValidatorTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
use Markup\AddressingBundle\Validator\MultipleRegexConstraint;
66
use Markup\AddressingBundle\Validator\MultipleRegexValidator;
77
use Mockery as m;
8+
use Symfony\Component\Validator\ConstraintValidatorInterface;
9+
use Symfony\Component\Validator\Context\ExecutionContextInterface;
810

911
class MultipleRegexValidatorTest extends \PHPUnit_Framework_TestCase
1012
{
1113
protected function setUp()
1214
{
1315
$this->validator = new MultipleRegexValidator();
14-
$this->context = m::mock('Symfony\Component\Validator\ExecutionContextInterface');
16+
$this->context = m::mock(ExecutionContextInterface::class);
1517
$this->validator->initialize($this->context);
1618
}
1719

@@ -22,7 +24,7 @@ protected function tearDown()
2224

2325
public function testIsConstraintValidator()
2426
{
25-
$this->assertInstanceOf('Symfony\Component\Validator\ConstraintValidatorInterface', $this->validator);
27+
$this->assertInstanceOf(ConstraintValidatorInterface::class, $this->validator);
2628
}
2729

2830
public function testPassingPostalCode()

Tests/Validator/RegexPostalCodeValidatorTest.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use Markup\AddressingBundle\Validator\PostalCodeConstraint;
66
use Markup\AddressingBundle\Validator\RegexPostalCodeValidator;
7+
use Symfony\Component\Validator\Constraint;
8+
use Symfony\Component\Validator\ConstraintValidatorInterface;
9+
use Symfony\Component\Validator\Context\ExecutionContextInterface;
710

811
/**
912
* A test for a validator for postal codes.
@@ -12,21 +15,21 @@ class RegexPostalCodeValidatorTest extends \PHPUnit_Framework_TestCase
1215
{
1316
public function setUp()
1417
{
15-
$this->regexValidator = $this->getMock('Symfony\Component\Validator\ConstraintValidatorInterface');
16-
$this->notBlankValidator = $this->getMock('Symfony\Component\Validator\ConstraintValidatorInterface');
18+
$this->regexValidator = $this->getMock(ConstraintValidatorInterface::class);
19+
$this->notBlankValidator = $this->getMock(ConstraintValidatorInterface::class);
1720
$this->validator = new RegexPostalCodeValidator($this->regexValidator, $this->notBlankValidator);
1821
}
1922

2023
public function testIsConstraintValidator()
2124
{
22-
$this->assertInstanceOf('Symfony\Component\Validator\ConstraintValidatorInterface', $this->validator);
25+
$this->assertInstanceOf(ConstraintValidatorInterface::class, $this->validator);
2326
}
2427

2528
public function testValidateInitializesAndDelegatesOnValidators()
2629
{
2730
$constraint = new PostalCodeConstraint();
2831
$constraint->message = 'message';
29-
$context = $this->getMock('Symfony\Component\Validator\ExecutionContextInterface');
32+
$context = $this->getMock(ExecutionContextInterface::class);
3033
$value = 'i am a value';
3134
$this->regexValidator
3235
->expects($this->at(0))
@@ -35,15 +38,15 @@ public function testValidateInitializesAndDelegatesOnValidators()
3538
$this->regexValidator
3639
->expects($this->at(1))
3740
->method('validate')
38-
->with($this->equalTo($value), $this->isInstanceOf('Symfony\Component\Validator\Constraint'));
41+
->with($this->equalTo($value), $this->isInstanceOf(Constraint::class));
3942
$this->notBlankValidator
4043
->expects($this->at(0))
4144
->method('initialize')
4245
->with($this->equalTo($context));
4346
$this->notBlankValidator
4447
->expects($this->at(1))
4548
->method('validate')
46-
->with($this->equalTo($value), $this->isInstanceOf('Symfony\Component\Validator\Constraint'));
49+
->with($this->equalTo($value), $this->isInstanceOf(Constraint::class));
4750
$this->validator->initialize($context);
4851
$this->validator->validate($value, $constraint);
4952
}

Tests/Validator/RegionValidatorTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
use Markup\AddressingBundle\Validator\RegionConstraint;
66
use Markup\AddressingBundle\Validator\RegionValidator;
77
use Mockery as m;
8+
use Symfony\Component\Validator\ConstraintValidatorInterface;
9+
use Symfony\Component\Validator\Context\ExecutionContextInterface;
810

911
class RegionValidatorTest extends \PHPUnit_Framework_TestCase
1012
{
1113
protected function setUp()
1214
{
1315
$this->useStrictRegions = true;
1416
$this->validator = new RegionValidator($this->useStrictRegions);
15-
$this->context = m::mock('Symfony\Component\Validator\ExecutionContextInterface');
17+
$this->context = m::mock(ExecutionContextInterface::class);
1618
$this->validator->initialize($this->context);
1719
}
1820

@@ -23,7 +25,7 @@ protected function tearDown()
2325

2426
public function testIsValidator()
2527
{
26-
$this->assertInstanceOf('Symfony\Component\Validator\ConstraintValidatorInterface', $this->validator);
28+
$this->assertInstanceOf(ConstraintValidatorInterface::class, $this->validator);
2729
}
2830

2931
public function testThrowInvalidArgumentExceptionWhenInvalid()

composer.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,18 @@
1515
}
1616
],
1717
"require": {
18+
"php": ">=5.5",
1819
"markup/addressing": "1.0.x-dev",
19-
"symfony/framework-bundle": "~2.3"
20+
"symfony/framework-bundle": "~2.7|~3.0"
2021
},
2122
"require-dev": {
22-
"symfony/validator": "~2.3",
23+
"symfony/validator": "~2.7|~3.0",
2324
"phpunit/phpunit": "4.*",
24-
"mockery/mockery": "~0.8.0"
25+
"mockery/mockery": "~0.8.0",
26+
"symfony/console": "~2.7|~3.0"
2527
},
2628
"suggests": {
27-
"symfony/validator": "~2.3"
29+
"symfony/validator": "~2.7|~3.0"
2830
},
2931
"autoload": {
3032
"psr-0": { "Markup\\AddressingBundle": "" }

0 commit comments

Comments
 (0)