Skip to content

Commit b04447c

Browse files
committed
Upgrade PHPUnit
1 parent 8adfbb7 commit b04447c

21 files changed

+112
-33
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
/.idea
55
composer.lock
66
vendor/
7+
/.phpunit.result.cache
78

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"psr/log": "^1.0"
3131
},
3232
"require-dev": {
33-
"phpunit/phpunit": "^4.8|^5.0",
33+
"phpunit/phpunit": "^7.0|^8.0",
3434
"jms/serializer": "^1.9|^2.0|^3.0",
3535
"goetas-webservices/xsd2php-runtime": "^0.2.8@dev",
3636
"symfony/validator": "^2.3.24|^3.0|^4.0",

tests/Converter/AbstractXsdConverterTest.php

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<?php
22
namespace GoetasWebservices\Xsd\XsdToPhp\Tests\Converter;
33

4+
use GoetasWebservices\Xsd\XsdToPhp\AbstractConverter;
45
use GoetasWebservices\Xsd\XsdToPhp\Naming\ShortNamingStrategy;
6+
use GoetasWebservices\Xsd\XsdToPhp\Tests\ReflectionUtils;
7+
use PHPUnit\Framework\Assert;
8+
use PHPUnit\Framework\TestCase;
59

6-
class AbstractXsdConverterTest extends \PHPUnit_Framework_TestCase
10+
class AbstractXsdConverterTest extends TestCase
711
{
812

913
/**
@@ -12,7 +16,7 @@ class AbstractXsdConverterTest extends \PHPUnit_Framework_TestCase
1216
*/
1317
protected $converter;
1418

15-
public function setUp()
19+
public function setUp(): void
1620
{
1721
$this->converter = $this->getMockForAbstractClass('GoetasWebservices\Xsd\XsdToPhp\AbstractConverter', [new ShortNamingStrategy()]);
1822
}
@@ -23,7 +27,7 @@ public function testAliases()
2327
};
2428
$this->converter->addAliasMap('http://www.example.com', "myType", $f);
2529

26-
$handlers = \PHPUnit_Framework_Assert::readAttribute($this->converter, 'typeAliases');
30+
$handlers = ReflectionUtils::getObjectAttribute($this->converter, 'typeAliases');
2731

2832
$this->assertArrayHasKey('http://www.example.com', $handlers);
2933
$this->assertArrayHasKey('myType', $exmpleHandlers = $handlers['http://www.example.com']);
@@ -32,7 +36,7 @@ public function testAliases()
3236

3337
public function testDefaultAliases()
3438
{
35-
$handlers = \PHPUnit_Framework_Assert::readAttribute($this->converter, 'typeAliases');
39+
$handlers = ReflectionUtils::getObjectAttribute($this->converter, 'typeAliases');
3640

3741
$this->assertArrayHasKey('http://www.w3.org/2001/XMLSchema', $handlers);
3842
$defaultHandlers = $handlers['http://www.w3.org/2001/XMLSchema'];
@@ -46,7 +50,7 @@ public function testNamespaces()
4650
{
4751
$this->converter->addNamespace('http://www.example.com', 'some\php\ns');
4852

49-
$namespaces = \PHPUnit_Framework_Assert::readAttribute($this->converter, 'namespaces');
53+
$namespaces = ReflectionUtils::getObjectAttribute($this->converter, 'namespaces');
5054

5155
$this->assertArrayHasKey('http://www.example.com', $namespaces);
5256
$this->assertEquals('some\php\ns', $namespaces['http://www.example.com']);

tests/Converter/JMS/Xsd2JmsBase.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
use GoetasWebservices\Xsd\XsdToPhp\Jms\YamlConverter;
55
use GoetasWebservices\Xsd\XsdToPhp\Naming\ShortNamingStrategy;
66
use GoetasWebservices\XML\XSDReader\SchemaReader;
7+
use PHPUnit\Framework\TestCase;
78

8-
abstract class Xsd2JmsBase extends \PHPUnit_Framework_TestCase
9+
abstract class Xsd2JmsBase extends TestCase
910
{
1011
/**
1112
*
@@ -19,7 +20,7 @@ abstract class Xsd2JmsBase extends \PHPUnit_Framework_TestCase
1920
*/
2021
protected $reader;
2122

22-
public function setUp()
23+
public function setUp(): void
2324
{
2425
$this->converter = new YamlConverter(new ShortNamingStrategy());
2526
$this->converter->addNamespace('http://www.example.com', "Example");

tests/Converter/PHP/Xsd2PhpBase.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
use GoetasWebservices\Xsd\XsdToPhp\Naming\ShortNamingStrategy;
55
use GoetasWebservices\Xsd\XsdToPhp\Php\PhpConverter;
66
use GoetasWebservices\XML\XSDReader\SchemaReader;
7+
use PHPUnit\Framework\TestCase;
78

8-
abstract class Xsd2PhpBase extends \PHPUnit_Framework_TestCase
9+
abstract class Xsd2PhpBase extends TestCase
910
{
1011
/**
1112
*
@@ -19,7 +20,7 @@ abstract class Xsd2PhpBase extends \PHPUnit_Framework_TestCase
1920
*/
2021
protected $reader;
2122

22-
public function setUp()
23+
public function setUp(): void
2324
{
2425
$this->converter = new PhpConverter(new ShortNamingStrategy());
2526
$this->converter->addNamespace('http://www.example.com', "Example");

tests/Converter/Validator/Xsd2ValidatorTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
use GoetasWebservices\Xsd\XsdToPhp\Jms\YamlValidatorConverter;
66
use GoetasWebservices\Xsd\XsdToPhp\Naming\ShortNamingStrategy;
77
use GoetasWebservices\XML\XSDReader\SchemaReader;
8+
use PHPUnit\Framework\TestCase;
89

9-
class Xsd2ValidatorTest extends \PHPUnit_Framework_TestCase
10+
class Xsd2ValidatorTest extends TestCase
1011
{
1112
/**
1213
* @var YamlValidatorConverter
@@ -21,7 +22,7 @@ class Xsd2ValidatorTest extends \PHPUnit_Framework_TestCase
2122
/**
2223
* Set up converter and reader properties
2324
*/
24-
public function setUp()
25+
public function setUp(): void
2526
{
2627
$this->converter = new YamlValidatorConverter(new ShortNamingStrategy());
2728
$this->converter->addNamespace('http://www.example.com', "Example");

tests/Issues/I111/I111Test.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
use GoetasWebservices\XML\XSDReader\SchemaReader;
55
use GoetasWebservices\Xsd\XsdToPhp\Jms\YamlConverter;
66
use GoetasWebservices\Xsd\XsdToPhp\Naming\ShortNamingStrategy;
7+
use PHPUnit\Framework\TestCase;
78

8-
class I111Test extends \PHPUnit_Framework_TestCase{
9+
class I111Test extends TestCase {
910

1011
public function testNamespace()
1112
{

tests/Issues/I22/I22Test.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
use GoetasWebservices\XML\XSDReader\SchemaReader;
55
use GoetasWebservices\Xsd\XsdToPhp\Jms\YamlConverter;
66
use GoetasWebservices\Xsd\XsdToPhp\Naming\ShortNamingStrategy;
7+
use PHPUnit\Framework\TestCase;
78

8-
class I22Test extends \PHPUnit_Framework_TestCase{
9+
class I22Test extends TestCase {
910

1011
public function testNamespace()
1112
{

tests/Issues/I26/I26Test.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
use GoetasWebservices\XML\XSDReader\SchemaReader;
66
use GoetasWebservices\Xsd\XsdToPhp\Jms\YamlConverter;
77
use GoetasWebservices\Xsd\XsdToPhp\Naming\ShortNamingStrategy;
8+
use PHPUnit\Framework\TestCase;
89

9-
class I26Test extends \PHPUnit_Framework_TestCase
10+
class I26Test extends TestCase
1011
{
1112
public function testSkipWhenEmptyOnOptionalAndRequiredLists()
1213
{

tests/Issues/I40/I40Test.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
use GoetasWebservices\Xsd\XsdToPhp\Php\Structure\PHPClass;
88
use GoetasWebservices\Xsd\XsdToPhp\Php\Structure\PHPProperty;
99
use GoetasWebservices\XML\XSDReader\SchemaReader;
10+
use PHPUnit\Framework\TestCase;
1011

11-
class I40Test extends \PHPUnit_Framework_TestCase
12+
class I40Test extends TestCase
1213
{
1314

1415
public function testMissingClass()

tests/Issues/I43/I43Test.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
use GoetasWebservices\Xsd\XsdToPhp\Php\PhpConverter;
77
use GoetasWebservices\XML\XSDReader\SchemaReader;
88
use GoetasWebservices\Xsd\XsdToPhp\Tests\Generator;
9+
use PHPUnit\Framework\TestCase;
910

10-
class I43Test extends \PHPUnit_Framework_TestCase
11+
class I43Test extends TestCase
1112
{
1213
/**
1314
* @group long

tests/Issues/I57/I57Test.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
use GoetasWebservices\Xsd\XsdToPhp\Naming\ShortNamingStrategy;
66
use GoetasWebservices\Xsd\XsdToPhp\Php\PhpConverter;
77
use GoetasWebservices\XML\XSDReader\SchemaReader;
8+
use PHPUnit\Framework\TestCase;
89

9-
class I57Test extends \PHPUnit_Framework_TestCase
10+
class I57Test extends TestCase
1011
{
1112

1213
public function testMissingClass()

tests/Issues/I63/I63Test.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
use GoetasWebservices\Xsd\XsdToPhp\Naming\ShortNamingStrategy;
55
use GoetasWebservices\Xsd\XsdToPhp\Php\PhpConverter;
66
use GoetasWebservices\XML\XSDReader\SchemaReader;
7+
use PHPUnit\Framework\TestCase;
78

8-
class I63Test extends \PHPUnit_Framework_TestCase
9+
class I63Test extends TestCase
910
{
1011

1112
public function testNaming()

tests/Issues/I84/I84Test.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
use GoetasWebservices\Xsd\XsdToPhp\Naming\ShortNamingStrategy;
55
use GoetasWebservices\Xsd\XsdToPhp\Php\PhpConverter;
66
use GoetasWebservices\XML\XSDReader\SchemaReader;
7+
use PHPUnit\Framework\TestCase;
78

8-
class I84Test extends \PHPUnit_Framework_TestCase
9+
class I84Test extends TestCase
910
{
1011

1112
public function testNaming()

tests/JmsSerializer/OTA/OTASerializationTest.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
use GoetasWebservices\Xsd\XsdToPhpRuntime\Jms\Handler\XmlSchemaDateHandler;
1111
use JMS\Serializer\Handler\HandlerRegistryInterface;
1212
use PackageVersions\Versions;
13+
use PHPUnit\Framework\TestCase;
1314
use Symfony\Component\Validator\Validator\ValidatorInterface;
1415

15-
class OTASerializationTest extends \PHPUnit_Framework_TestCase
16+
class OTASerializationTest extends TestCase
1617
{
1718
/**
1819
* @var Generator
@@ -27,7 +28,7 @@ class OTASerializationTest extends \PHPUnit_Framework_TestCase
2728
private static $namespace = 'OTA';
2829
private static $files = [];
2930

30-
public static function setUpBeforeClass()
31+
public static function setUpBeforeClass(): void
3132
{
3233
if (!self::$files) {
3334
self::$files = self::getXmlFiles();
@@ -53,7 +54,7 @@ public static function setUpBeforeClass()
5354
self::$validator = self::$generator->getValidator($schemas);
5455
}
5556

56-
public static function tearDownAfterClass()
57+
public static function tearDownAfterClass(): void
5758
{
5859
self::$generator->unRegisterAutoloader();
5960
self::$generator->cleanDirectories();
@@ -203,6 +204,8 @@ public function testValidation($xml, $xsd, $class)
203204

204205
if (@$xmlDom->schemaValidate($xsd)) {
205206
$this->assertCount(0, $violations, 'Validation errors in '.$xml);
207+
} else {
208+
$this->assertTrue(true);
206209
}
207210
}
208211

tests/PHP/AnyTypePHPConversionTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
use GoetasWebservices\Xsd\XsdToPhp\Php\ClassGenerator;
77
use GoetasWebservices\Xsd\XsdToPhp\Php\PhpConverter;
88
use GoetasWebservices\XML\XSDReader\SchemaReader;
9+
use PHPUnit\Framework\TestCase;
910

10-
class AnyTypePHPConversionTest extends \PHPUnit_Framework_TestCase
11+
class AnyTypePHPConversionTest extends TestCase
1112
{
1213

1314
/**

tests/PHP/PHPConversionTest.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
use GoetasWebservices\Xsd\XsdToPhp\Php\ClassGenerator;
66
use GoetasWebservices\Xsd\XsdToPhp\Php\PhpConverter;
77
use GoetasWebservices\XML\XSDReader\SchemaReader;
8+
use PHPUnit\Framework\TestCase;
89

9-
class PHPConversionTest extends \PHPUnit_Framework_TestCase
10+
class PHPConversionTest extends TestCase
1011
{
1112

1213
/**

tests/PathGenerator/JMSPathGeneratorTest.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
namespace GoetasWebservices\Xsd\XsdToPhp\Tests\Php\PathGenerator;
33

44
use GoetasWebservices\Xsd\XsdToPhp\Jms\PathGenerator\Psr4PathGenerator;
5+
use PHPUnit\Framework\TestCase;
56

6-
class JMSPathGeneratorTest extends \PHPUnit_Framework_TestCase
7+
class JMSPathGeneratorTest extends TestCase
78
{
89
protected $tmpdir;
910

10-
public function setUp()
11+
public function setUp(): void
1112
{
1213
$tmp = sys_get_temp_dir();
1314

@@ -23,7 +24,7 @@ public function setUp()
2324

2425
public function testNoNs()
2526
{
26-
$this->setExpectedException('GoetasWebservices\Xsd\XsdToPhp\PathGenerator\PathGeneratorException');
27+
$this->expectException('GoetasWebservices\Xsd\XsdToPhp\PathGenerator\PathGeneratorException');
2728
$generator = new Psr4PathGenerator(array(
2829
'myns2\\' => $this->tmpdir
2930
));

tests/PathGenerator/PHPPathGeneratorTest.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
use GoetasWebservices\Xsd\XsdToPhp\Php\PathGenerator\Psr4PathGenerator;
55
use GoetasWebservices\Xsd\XsdToPhp\Php\Structure\PHPClass;
66
use Laminas\Code\Generator\ClassGenerator;
7+
use PHPUnit\Framework\TestCase;
78

8-
class PHPPathGeneratorTest extends \PHPUnit_Framework_TestCase
9+
class PHPPathGeneratorTest extends TestCase
910
{
1011
protected $tmpdir;
1112

12-
public function setUp()
13+
public function setUp(): void
1314
{
1415
$tmp = sys_get_temp_dir();
1516

@@ -25,7 +26,7 @@ public function setUp()
2526

2627
public function testNoNs()
2728
{
28-
$this->setExpectedException('GoetasWebservices\Xsd\XsdToPhp\PathGenerator\PathGeneratorException');
29+
$this->expectException('GoetasWebservices\Xsd\XsdToPhp\PathGenerator\PathGeneratorException');
2930
$generator = new Psr4PathGenerator(array(
3031
'myns\\' => $this->tmpdir
3132
));

tests/ReflectionUtils.php

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
4+
namespace GoetasWebservices\Xsd\XsdToPhp\Tests;
5+
6+
7+
use PHPUnit\Framework\Exception;
8+
use PHPUnit\Framework\InvalidArgumentException;
9+
use ReflectionObject;
10+
11+
class ReflectionUtils
12+
{
13+
/**
14+
* Returns the value of an object's attribute.
15+
* This also works for attributes that are declared protected or private.
16+
*
17+
* @param object $object
18+
*
19+
* @throws Exception
20+
*
21+
* @codeCoverageIgnore
22+
*/
23+
public static function getObjectAttribute($object, string $attributeName)
24+
{
25+
if (!\is_object($object)) {
26+
throw InvalidArgumentException::create(1, 'object');
27+
}
28+
29+
$reflector = new ReflectionObject($object);
30+
31+
do {
32+
try {
33+
$attribute = $reflector->getProperty($attributeName);
34+
35+
if (!$attribute || $attribute->isPublic()) {
36+
return $object->$attributeName;
37+
}
38+
39+
$attribute->setAccessible(true);
40+
$value = $attribute->getValue($object);
41+
$attribute->setAccessible(false);
42+
43+
return $value;
44+
} catch (\ReflectionException $e) {
45+
}
46+
} while ($reflector = $reflector->getParentClass());
47+
48+
throw new Exception(
49+
\sprintf(
50+
'Attribute "%s" not found in object.',
51+
$attributeName
52+
)
53+
);
54+
}
55+
}

0 commit comments

Comments
 (0)