Skip to content

Commit

Permalink
Merge pull request #144 from DanielGSoftware/master
Browse files Browse the repository at this point in the history
Allow phpunit 9 & update doctrine/inflect to ^2.0
  • Loading branch information
goetas committed Feb 10, 2022
2 parents 37ee806 + 93a78d4 commit 33814ba
Show file tree
Hide file tree
Showing 29 changed files with 110 additions and 70 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ php:
- 7.2
- 7.3
- 7.4
- 8.0
- 8.1

matrix:
include:
Expand Down
20 changes: 10 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@
],
"license": "MIT",
"require": {
"php": ">=7.1",
"symfony/console": "^2.7|^3.0|^4.0|^5.0",
"symfony/dependency-injection": "^2.2|^3.0|^4.0|^5.0",
"symfony/yaml": "^2.2|^3.0|^4.0|^5.0",
"symfony/config": "^2.2|^3.0|^4.0|^5.0",
"php": ">=7.2",
"symfony/console": "^2.7|^3.0|^4.0|^5.0|^6.0",
"symfony/dependency-injection": "^2.2|^3.0|^4.0|^5.0|^6.0",
"symfony/yaml": "^2.2|^3.0|^4.0|^5.0|^6.0",
"symfony/config": "^2.2|^3.0|^4.0|^5.0|^6.0",
"goetas-webservices/xsd-reader": "^0.3.7",
"doctrine/inflector": "^1.0",
"laminas/laminas-code": "^3.3.2",

"doctrine/inflector": "^2.0",
"laminas/laminas-code": "^3.3.2|^4.0",
"psr/log": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^5.0",
"phpunit/phpunit": "^6.0|^7.0|^8.0|^9.0",
"jms/serializer": "^1.9|^2.0|^3.0",
"goetas-webservices/xsd2php-runtime": "^0.2.13@dev",
"symfony/validator": "^2.3.24|^3.0|^4.0"
"symfony/validator": "^2.3.24|^3.0|^4.0|^5.0|^6.0",
"dms/phpunit-arraysubset-asserts": "^0.3.1"
},
"autoload": {
"psr-4": {
Expand Down
5 changes: 5 additions & 0 deletions src/AbstractConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public function addAliasMapType($ns, $name, $type)
});
}

public function getTypeAliases(): array
{
return $this->typeAliases;
}

public function getTypeAlias($type, Schema $schemapos = null)
{
$schema = $schemapos ?: $type->getSchema();
Expand Down
12 changes: 7 additions & 5 deletions src/Jms/YamlConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace GoetasWebservices\Xsd\XsdToPhp\Jms;

use Doctrine\Common\Inflector\Inflector;
use Doctrine\Inflector\InflectorFactory;
use Exception;
use GoetasWebservices\XML\XSDReader\Schema\Attribute\AttributeContainer;
use GoetasWebservices\XML\XSDReader\Schema\Attribute\AttributeItem;
Expand Down Expand Up @@ -379,8 +379,9 @@ protected function &visitAttribute(&$class, Schema $schema, AttributeItem $attri
$property['access_type'] = 'public_method';
$property['serialized_name'] = $attribute->getName();

$property['accessor']['getter'] = 'get' . Inflector::classify($this->getNamingStrategy()->getPropertyName($attribute));
$property['accessor']['setter'] = 'set' . Inflector::classify($this->getNamingStrategy()->getPropertyName($attribute));
$inflector = InflectorFactory::create()->build();
$property['accessor']['getter'] = 'get' . $inflector->classify($this->getNamingStrategy()->getPropertyName($attribute));
$property['accessor']['setter'] = 'set' . $inflector->classify($this->getNamingStrategy()->getPropertyName($attribute));

$property['xml_attribute'] = true;

Expand Down Expand Up @@ -496,8 +497,9 @@ protected function &visitElement(&$class, Schema $schema, ElementItem $element,
$property['xml_element']['namespace'] = $elementNamespace;
}

$property['accessor']['getter'] = 'get' . Inflector::classify($this->getNamingStrategy()->getPropertyName($element));
$property['accessor']['setter'] = 'set' . Inflector::classify($this->getNamingStrategy()->getPropertyName($element));
$inflector = InflectorFactory::create()->build();
$property['accessor']['getter'] = 'get' . $inflector->classify($this->getNamingStrategy()->getPropertyName($element));
$property['accessor']['setter'] = 'set' . $inflector->classify($this->getNamingStrategy()->getPropertyName($element));
$t = $element->getType();

if ($arrayize) {
Expand Down
10 changes: 7 additions & 3 deletions src/Naming/AbstractNamingStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace GoetasWebservices\Xsd\XsdToPhp\Naming;

use Doctrine\Common\Inflector\Inflector;
use Doctrine\Inflector\InflectorFactory;
use GoetasWebservices\XML\XSDReader\Schema\Item;
use GoetasWebservices\XML\XSDReader\Schema\Type\Type;

Expand Down Expand Up @@ -99,11 +99,15 @@ public function getItemName(Item $item)

public function getPropertyName($item)
{
return Inflector::camelize(str_replace('.', ' ', $item->getName()));
$inflector = InflectorFactory::create()->build();

return $inflector->camelize(str_replace('.', ' ', $item->getName()));
}

protected function classify($name)
{
return Inflector::classify(str_replace('.', ' ', $name));
$inflector = InflectorFactory::create()->build();

return $inflector->classify(str_replace('.', ' ', $name));
}
}
1 change: 0 additions & 1 deletion src/Naming/LongNamingStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace GoetasWebservices\Xsd\XsdToPhp\Naming;

use Doctrine\Common\Inflector\Inflector;
use GoetasWebservices\XML\XSDReader\Schema\Item;
use GoetasWebservices\XML\XSDReader\Schema\Type\Type;

Expand Down
1 change: 0 additions & 1 deletion src/Naming/NoConflictLongNamingStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace GoetasWebservices\Xsd\XsdToPhp\Naming;

use Doctrine\Common\Inflector\Inflector;
use GoetasWebservices\XML\XSDReader\Schema\Item;
use GoetasWebservices\XML\XSDReader\Schema\Type\Type;

Expand Down
1 change: 0 additions & 1 deletion src/Naming/ShortNamingStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace GoetasWebservices\Xsd\XsdToPhp\Naming;

use Doctrine\Common\Inflector\Inflector;
use GoetasWebservices\XML\XSDReader\Schema\Item;
use GoetasWebservices\XML\XSDReader\Schema\Type\Type;

Expand Down
17 changes: 11 additions & 6 deletions src/Php/ClassGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace GoetasWebservices\Xsd\XsdToPhp\Php;

use Doctrine\Common\Inflector\Inflector;
use Doctrine\Inflector\InflectorFactory;
use GoetasWebservices\Xsd\XsdToPhp\Php\Structure\PHPClass;
use GoetasWebservices\Xsd\XsdToPhp\Php\Structure\PHPClassOf;
use GoetasWebservices\Xsd\XsdToPhp\Php\Structure\PHPProperty;
Expand Down Expand Up @@ -125,7 +125,8 @@ private function handleSetter(Generator\ClassGenerator $generator, PHPProperty $

$type = $prop->getType();

$method = new MethodGenerator('set' . Inflector::classify($prop->getName()));
$inflector = InflectorFactory::create()->build();
$method = new MethodGenerator('set' . $inflector->classify($prop->getName()));

$parameter = new ParameterGenerator($prop->getName());

Expand Down Expand Up @@ -171,6 +172,8 @@ private function handleSetter(Generator\ClassGenerator $generator, PHPProperty $

private function handleGetter(Generator\ClassGenerator $generator, PHPProperty $prop, PHPClass $class)
{
$inflector = InflectorFactory::create()->build();

if ($prop->getType() instanceof PHPClassOf) {
$docblock = new DocBlockGenerator();
$docblock->setWordWrap(false);
Expand All @@ -186,7 +189,8 @@ private function handleGetter(Generator\ClassGenerator $generator, PHPProperty $

$paramIndex = new ParameterGenerator('index');

$method = new MethodGenerator('isset' . Inflector::classify($prop->getName()), [$paramIndex]);

$method = new MethodGenerator('isset' . $inflector->classify($prop->getName()), [$paramIndex]);
$method->setDocBlock($docblock);
$method->setBody('return isset($this->' . $prop->getName() . '[$index]);');
$generator->addMethodFromGenerator($method);
Expand All @@ -204,7 +208,7 @@ private function handleGetter(Generator\ClassGenerator $generator, PHPProperty $

$docblock->setTag(new ReturnTag('void'));

$method = new MethodGenerator('unset' . Inflector::classify($prop->getName()), [$paramIndex]);
$method = new MethodGenerator('unset' . $inflector->classify($prop->getName()), [$paramIndex]);
$method->setDocBlock($docblock);
$method->setBody('unset($this->' . $prop->getName() . '[$index]);');
$generator->addMethodFromGenerator($method);
Expand Down Expand Up @@ -242,7 +246,7 @@ private function handleGetter(Generator\ClassGenerator $generator, PHPProperty $

$docblock->setTag($tag);

$method = new MethodGenerator('get' . Inflector::classify($prop->getName()));
$method = new MethodGenerator('get' . $inflector->classify($prop->getName()));
$method->setDocBlock($docblock);
$method->setBody('return $this->' . $prop->getName() . ';');

Expand All @@ -269,7 +273,8 @@ private function handleAdder(Generator\ClassGenerator $generator, PHPProperty $p
$patramTag = new ParamTag($propName, $type->getArg()->getType()->getPhpType());
$docblock->setTag($patramTag);

$method = new MethodGenerator('addTo' . Inflector::classify($prop->getName()));
$inflector = InflectorFactory::create()->build();
$method = new MethodGenerator('addTo' . $inflector->classify($prop->getName()));

$parameter = new ParameterGenerator($propName);
$tt = $type->getArg()->getType();
Expand Down
14 changes: 8 additions & 6 deletions tests/Converter/AbstractXsdConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@

namespace GoetasWebservices\Xsd\XsdToPhp\Tests\Converter;

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

class AbstractXsdConverterTest extends \PHPUnit_Framework_TestCase
class AbstractXsdConverterTest extends TestCase
{
/**
* @var AbstractConverter
*/
protected $converter;

public function setUp()
public function setUp(): void
{
$this->converter = $this->getMockForAbstractClass('GoetasWebservices\Xsd\XsdToPhp\AbstractConverter', [new ShortNamingStrategy()]);
$this->converter = $this->getMockForAbstractClass(AbstractConverter::class, [new ShortNamingStrategy()]);
}

public function testAliases()
Expand All @@ -22,7 +24,7 @@ public function testAliases()
};
$this->converter->addAliasMap('http://www.example.com', 'myType', $f);

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

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

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

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

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

$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 @@ -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;

abstract class Xsd2JmsBase extends \PHPUnit_Framework_TestCase
abstract class Xsd2JmsBase extends TestCase
{
/**
* @var YamlConverter
Expand All @@ -18,7 +19,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 @@ -5,8 +5,9 @@
use GoetasWebservices\XML\XSDReader\SchemaReader;
use GoetasWebservices\Xsd\XsdToPhp\Naming\ShortNamingStrategy;
use GoetasWebservices\Xsd\XsdToPhp\Php\PhpConverter;
use PHPUnit\Framework\TestCase;

abstract class Xsd2PhpBase extends \PHPUnit_Framework_TestCase
abstract class Xsd2PhpBase extends TestCase
{
/**
* @var PhpConverter
Expand All @@ -18,7 +19,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\XML\XSDReader\SchemaReader;
use GoetasWebservices\Xsd\XsdToPhp\Jms\YamlValidatorConverter;
use GoetasWebservices\Xsd\XsdToPhp\Naming\ShortNamingStrategy;
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 @@ -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 I111Test extends \PHPUnit_Framework_TestCase
class I111Test extends TestCase
{
public function testNamespace()
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Issues/I138/I138Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
use GoetasWebservices\Xsd\XsdToPhp\Naming\ShortNamingStrategy;
use GoetasWebservices\Xsd\XsdToPhp\Php\PhpConverter;
use GoetasWebservices\XML\XSDReader\SchemaReader;
use PHPUnit\Framework\TestCase;

class I138Test extends \PHPUnit_Framework_TestCase
class I138Test extends TestCase
{

public function testChioce()
{
$reader = new SchemaReader();
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 @@ -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 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

0 comments on commit 33814ba

Please sign in to comment.