Skip to content

Commit

Permalink
Upgrade PHPUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
Toilal committed Aug 23, 2020
1 parent d406337 commit 02be40c
Show file tree
Hide file tree
Showing 21 changed files with 112 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
/.idea
composer.lock
vendor/
/.phpunit.result.cache

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"psr/log": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8|^5.0",
"phpunit/phpunit": "^7.0|^8.0",
"jms/serializer": "^1.9|^2.0|^3.0",
"goetas-webservices/xsd2php-runtime": "^0.2.8@dev",
"symfony/validator": "^2.3.24|^3.0|^4.0",
Expand Down
14 changes: 9 additions & 5 deletions tests/Converter/AbstractXsdConverterTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<?php
namespace GoetasWebservices\Xsd\XsdToPhp\Tests\Converter;

use GoetasWebservices\Xsd\XsdToPhp\AbstractConverter;
use GoetasWebservices\Xsd\XsdToPhp\Naming\ShortNamingStrategy;
use GoetasWebservices\Xsd\XsdToPhp\Tests\ReflectionUtils;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;

class AbstractXsdConverterTest extends \PHPUnit_Framework_TestCase
class AbstractXsdConverterTest extends TestCase
{

/**
Expand All @@ -12,7 +16,7 @@ class AbstractXsdConverterTest extends \PHPUnit_Framework_TestCase
*/
protected $converter;

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

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

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

public function testDefaultAliases()
{
$handlers = \PHPUnit_Framework_Assert::readAttribute($this->converter, 'typeAliases');
$handlers = ReflectionUtils::getObjectAttribute($this->converter, 'typeAliases');

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

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

$this->assertArrayHasKey('http://www.example.com', $namespaces);
$this->assertEquals('some\php\ns', $namespaces['http://www.example.com']);
Expand Down
5 changes: 3 additions & 2 deletions tests/Converter/JMS/Xsd2JmsBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
use GoetasWebservices\Xsd\XsdToPhp\Jms\YamlConverter;
use GoetasWebservices\Xsd\XsdToPhp\Naming\ShortNamingStrategy;
use GoetasWebservices\XML\XSDReader\SchemaReader;
use PHPUnit\Framework\TestCase;

abstract class Xsd2JmsBase extends \PHPUnit_Framework_TestCase
abstract class Xsd2JmsBase extends TestCase
{
/**
*
Expand All @@ -19,7 +20,7 @@ abstract class Xsd2JmsBase extends \PHPUnit_Framework_TestCase
*/
protected $reader;

public function setUp()
public function setUp(): void
{
$this->converter = new YamlConverter(new ShortNamingStrategy());
$this->converter->addNamespace('http://www.example.com', "Example");
Expand Down
5 changes: 3 additions & 2 deletions tests/Converter/PHP/Xsd2PhpBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
use GoetasWebservices\Xsd\XsdToPhp\Naming\ShortNamingStrategy;
use GoetasWebservices\Xsd\XsdToPhp\Php\PhpConverter;
use GoetasWebservices\XML\XSDReader\SchemaReader;
use PHPUnit\Framework\TestCase;

abstract class Xsd2PhpBase extends \PHPUnit_Framework_TestCase
abstract class Xsd2PhpBase extends TestCase
{
/**
*
Expand All @@ -19,7 +20,7 @@ abstract class Xsd2PhpBase extends \PHPUnit_Framework_TestCase
*/
protected $reader;

public function setUp()
public function setUp(): void
{
$this->converter = new PhpConverter(new ShortNamingStrategy());
$this->converter->addNamespace('http://www.example.com', "Example");
Expand Down
5 changes: 3 additions & 2 deletions tests/Converter/Validator/Xsd2ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
use GoetasWebservices\Xsd\XsdToPhp\Jms\YamlValidatorConverter;
use GoetasWebservices\Xsd\XsdToPhp\Naming\ShortNamingStrategy;
use GoetasWebservices\XML\XSDReader\SchemaReader;
use PHPUnit\Framework\TestCase;

class Xsd2ValidatorTest extends \PHPUnit_Framework_TestCase
class Xsd2ValidatorTest extends TestCase
{
/**
* @var YamlValidatorConverter
Expand All @@ -21,7 +22,7 @@ class Xsd2ValidatorTest extends \PHPUnit_Framework_TestCase
/**
* Set up converter and reader properties
*/
public function setUp()
public function setUp(): void
{
$this->converter = new YamlValidatorConverter(new ShortNamingStrategy());
$this->converter->addNamespace('http://www.example.com', "Example");
Expand Down
3 changes: 2 additions & 1 deletion tests/Issues/I111/I111Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
use GoetasWebservices\XML\XSDReader\SchemaReader;
use GoetasWebservices\Xsd\XsdToPhp\Jms\YamlConverter;
use GoetasWebservices\Xsd\XsdToPhp\Naming\ShortNamingStrategy;
use PHPUnit\Framework\TestCase;

class I111Test extends \PHPUnit_Framework_TestCase{
class I111Test extends TestCase {

public function testNamespace()
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Issues/I22/I22Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
use GoetasWebservices\XML\XSDReader\SchemaReader;
use GoetasWebservices\Xsd\XsdToPhp\Jms\YamlConverter;
use GoetasWebservices\Xsd\XsdToPhp\Naming\ShortNamingStrategy;
use PHPUnit\Framework\TestCase;

class I22Test extends \PHPUnit_Framework_TestCase{
class I22Test extends TestCase {

public function testNamespace()
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Issues/I26/I26Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
use GoetasWebservices\XML\XSDReader\SchemaReader;
use GoetasWebservices\Xsd\XsdToPhp\Jms\YamlConverter;
use GoetasWebservices\Xsd\XsdToPhp\Naming\ShortNamingStrategy;
use PHPUnit\Framework\TestCase;

class I26Test extends \PHPUnit_Framework_TestCase
class I26Test extends TestCase
{
public function testSkipWhenEmptyOnOptionalAndRequiredLists()
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Issues/I40/I40Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
use GoetasWebservices\Xsd\XsdToPhp\Php\Structure\PHPClass;
use GoetasWebservices\Xsd\XsdToPhp\Php\Structure\PHPProperty;
use GoetasWebservices\XML\XSDReader\SchemaReader;
use PHPUnit\Framework\TestCase;

class I40Test extends \PHPUnit_Framework_TestCase
class I40Test extends TestCase
{

public function testMissingClass()
Expand Down
3 changes: 2 additions & 1 deletion tests/Issues/I43/I43Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
use GoetasWebservices\Xsd\XsdToPhp\Php\PhpConverter;
use GoetasWebservices\XML\XSDReader\SchemaReader;
use GoetasWebservices\Xsd\XsdToPhp\Tests\Generator;
use PHPUnit\Framework\TestCase;

class I43Test extends \PHPUnit_Framework_TestCase
class I43Test extends TestCase
{
/**
* @group long
Expand Down
3 changes: 2 additions & 1 deletion tests/Issues/I57/I57Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
use GoetasWebservices\Xsd\XsdToPhp\Naming\ShortNamingStrategy;
use GoetasWebservices\Xsd\XsdToPhp\Php\PhpConverter;
use GoetasWebservices\XML\XSDReader\SchemaReader;
use PHPUnit\Framework\TestCase;

class I57Test extends \PHPUnit_Framework_TestCase
class I57Test extends TestCase
{

public function testMissingClass()
Expand Down
3 changes: 2 additions & 1 deletion tests/Issues/I63/I63Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
use GoetasWebservices\Xsd\XsdToPhp\Naming\ShortNamingStrategy;
use GoetasWebservices\Xsd\XsdToPhp\Php\PhpConverter;
use GoetasWebservices\XML\XSDReader\SchemaReader;
use PHPUnit\Framework\TestCase;

class I63Test extends \PHPUnit_Framework_TestCase
class I63Test extends TestCase
{

public function testNaming()
Expand Down
3 changes: 2 additions & 1 deletion tests/Issues/I84/I84Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
use GoetasWebservices\Xsd\XsdToPhp\Naming\ShortNamingStrategy;
use GoetasWebservices\Xsd\XsdToPhp\Php\PhpConverter;
use GoetasWebservices\XML\XSDReader\SchemaReader;
use PHPUnit\Framework\TestCase;

class I84Test extends \PHPUnit_Framework_TestCase
class I84Test extends TestCase
{

public function testNaming()
Expand Down
9 changes: 6 additions & 3 deletions tests/JmsSerializer/OTA/OTASerializationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
use GoetasWebservices\Xsd\XsdToPhpRuntime\Jms\Handler\XmlSchemaDateHandler;
use JMS\Serializer\Handler\HandlerRegistryInterface;
use PackageVersions\Versions;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Validator\Validator\ValidatorInterface;

class OTASerializationTest extends \PHPUnit_Framework_TestCase
class OTASerializationTest extends TestCase
{
/**
* @var Generator
Expand All @@ -27,7 +28,7 @@ class OTASerializationTest extends \PHPUnit_Framework_TestCase
private static $namespace = 'OTA';
private static $files = [];

public static function setUpBeforeClass()
public static function setUpBeforeClass(): void
{
if (!self::$files) {
self::$files = self::getXmlFiles();
Expand All @@ -53,7 +54,7 @@ public static function setUpBeforeClass()
self::$validator = self::$generator->getValidator($schemas);
}

public static function tearDownAfterClass()
public static function tearDownAfterClass(): void
{
self::$generator->unRegisterAutoloader();
self::$generator->cleanDirectories();
Expand Down Expand Up @@ -203,6 +204,8 @@ public function testValidation($xml, $xsd, $class)

if (@$xmlDom->schemaValidate($xsd)) {
$this->assertCount(0, $violations, 'Validation errors in '.$xml);
} else {
$this->assertTrue(true);
}
}

Expand Down
3 changes: 2 additions & 1 deletion tests/PHP/AnyTypePHPConversionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
use GoetasWebservices\Xsd\XsdToPhp\Php\ClassGenerator;
use GoetasWebservices\Xsd\XsdToPhp\Php\PhpConverter;
use GoetasWebservices\XML\XSDReader\SchemaReader;
use PHPUnit\Framework\TestCase;

class AnyTypePHPConversionTest extends \PHPUnit_Framework_TestCase
class AnyTypePHPConversionTest extends TestCase
{

/**
Expand Down
3 changes: 2 additions & 1 deletion tests/PHP/PHPConversionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
use GoetasWebservices\Xsd\XsdToPhp\Php\ClassGenerator;
use GoetasWebservices\Xsd\XsdToPhp\Php\PhpConverter;
use GoetasWebservices\XML\XSDReader\SchemaReader;
use PHPUnit\Framework\TestCase;

class PHPConversionTest extends \PHPUnit_Framework_TestCase
class PHPConversionTest extends TestCase
{

/**
Expand Down
7 changes: 4 additions & 3 deletions tests/PathGenerator/JMSPathGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
namespace GoetasWebservices\Xsd\XsdToPhp\Tests\Php\PathGenerator;

use GoetasWebservices\Xsd\XsdToPhp\Jms\PathGenerator\Psr4PathGenerator;
use PHPUnit\Framework\TestCase;

class JMSPathGeneratorTest extends \PHPUnit_Framework_TestCase
class JMSPathGeneratorTest extends TestCase
{
protected $tmpdir;

public function setUp()
public function setUp(): void
{
$tmp = sys_get_temp_dir();

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

public function testNoNs()
{
$this->setExpectedException('GoetasWebservices\Xsd\XsdToPhp\PathGenerator\PathGeneratorException');
$this->expectException('GoetasWebservices\Xsd\XsdToPhp\PathGenerator\PathGeneratorException');
$generator = new Psr4PathGenerator(array(
'myns2\\' => $this->tmpdir
));
Expand Down
7 changes: 4 additions & 3 deletions tests/PathGenerator/PHPPathGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
use GoetasWebservices\Xsd\XsdToPhp\Php\PathGenerator\Psr4PathGenerator;
use GoetasWebservices\Xsd\XsdToPhp\Php\Structure\PHPClass;
use Laminas\Code\Generator\ClassGenerator;
use PHPUnit\Framework\TestCase;

class PHPPathGeneratorTest extends \PHPUnit_Framework_TestCase
class PHPPathGeneratorTest extends TestCase
{
protected $tmpdir;

public function setUp()
public function setUp(): void
{
$tmp = sys_get_temp_dir();

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

public function testNoNs()
{
$this->setExpectedException('GoetasWebservices\Xsd\XsdToPhp\PathGenerator\PathGeneratorException');
$this->expectException('GoetasWebservices\Xsd\XsdToPhp\PathGenerator\PathGeneratorException');
$generator = new Psr4PathGenerator(array(
'myns\\' => $this->tmpdir
));
Expand Down
55 changes: 55 additions & 0 deletions tests/ReflectionUtils.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php


namespace GoetasWebservices\Xsd\XsdToPhp\Tests;


use PHPUnit\Framework\Exception;
use PHPUnit\Framework\InvalidArgumentException;
use ReflectionObject;

class ReflectionUtils
{
/**
* Returns the value of an object's attribute.
* This also works for attributes that are declared protected or private.
*
* @param object $object
*
* @throws Exception
*
* @codeCoverageIgnore
*/
public static function getObjectAttribute($object, string $attributeName)
{
if (!\is_object($object)) {
throw InvalidArgumentException::create(1, 'object');
}

$reflector = new ReflectionObject($object);

do {
try {
$attribute = $reflector->getProperty($attributeName);

if (!$attribute || $attribute->isPublic()) {
return $object->$attributeName;
}

$attribute->setAccessible(true);
$value = $attribute->getValue($object);
$attribute->setAccessible(false);

return $value;
} catch (\ReflectionException $e) {
}
} while ($reflector = $reflector->getParentClass());

throw new Exception(
\sprintf(
'Attribute "%s" not found in object.',
$attributeName
)
);
}
}
Loading

0 comments on commit 02be40c

Please sign in to comment.