diff --git a/src/Php/PathGenerator/Psr4PathGenerator.php b/src/Php/PathGenerator/Psr4PathGenerator.php index 1c61cd49..a9ac8463 100644 --- a/src/Php/PathGenerator/Psr4PathGenerator.php +++ b/src/Php/PathGenerator/Psr4PathGenerator.php @@ -22,7 +22,7 @@ public function getPath(ClassGenerator $php) } } - throw new PathGeneratorException("Can't find a defined location where save '$php' object"); + throw new PathGeneratorException("Can't find a defined location where save '{$php->getNamespaceName()}\\{$php->getName()}' object"); } } diff --git a/tests/AbstractGenerator.php b/tests/AbstractGenerator.php index be60ea74..3e794cf7 100644 --- a/tests/AbstractGenerator.php +++ b/tests/AbstractGenerator.php @@ -5,8 +5,10 @@ use GoetasWebservices\Xsd\XsdToPhp\AbstractConverter; use GoetasWebservices\Xsd\XsdToPhp\Jms\PathGenerator\Psr4PathGenerator as JmsPsr4PathGenerator; use GoetasWebservices\Xsd\XsdToPhp\Naming\ShortNamingStrategy; +use GoetasWebservices\Xsd\XsdToPhp\Php\ClassGenerator; use GoetasWebservices\Xsd\XsdToPhp\Php\PathGenerator\Psr4PathGenerator as PhpPsr4PathGenerator; use GoetasWebservices\Xsd\XsdToPhp\Writer\JMSWriter; +use GoetasWebservices\Xsd\XsdToPhp\Writer\PHPClassWriter; use GoetasWebservices\Xsd\XsdToPhp\Writer\PHPWriter; use JMS\Serializer\Handler\HandlerRegistryInterface; @@ -128,7 +130,8 @@ protected function writePHP(array $items) $pathGenerator = new PhpPsr4PathGenerator($paths); - $writer = new PHPWriter($pathGenerator); + $classWriter = new PHPClassWriter($pathGenerator); + $writer = new PHPWriter($classWriter, new ClassGenerator()); $writer->write($items); } @@ -147,4 +150,4 @@ protected function writeJMS(array $items) $writer = new JMSWriter($pathGenerator); $writer->write($items); } -} \ No newline at end of file +} diff --git a/tests/PHP/AnyTypePHPConversionTest.php b/tests/PHP/AnyTypePHPConversionTest.php index 68ff77a3..42959569 100644 --- a/tests/PHP/AnyTypePHPConversionTest.php +++ b/tests/PHP/AnyTypePHPConversionTest.php @@ -72,8 +72,7 @@ protected function getPhpClasses($xml, array $types = array()) $classes = array(); foreach ($items as $k => $item) { - $codegen = new \Zend\Code\Generator\ClassGenerator(); - if ($generator->generate($codegen, $item)) { + if ($codegen = $generator->generate($item)) { $classes[$k] = $codegen; } } @@ -146,4 +145,4 @@ public function testSimpleAnyTypeYaml() ) ), $single); } -} \ No newline at end of file +} diff --git a/tests/PHP/PHPConversionTest.php b/tests/PHP/PHPConversionTest.php index c39918e2..78cc54a8 100644 --- a/tests/PHP/PHPConversionTest.php +++ b/tests/PHP/PHPConversionTest.php @@ -35,8 +35,7 @@ protected function getClasses($xml) $classes = array(); foreach ($items as $k => $item) { - $codegen = new \Zend\Code\Generator\ClassGenerator(); - if ($generator->generate($codegen, $item)) { + if ($codegen = $generator->generate($item)) { $classes[$k] = $codegen; } } @@ -245,4 +244,4 @@ public function testSimpleMulteplicity() $this->assertTrue($single->hasMethod('getId')); $this->assertTrue($single->hasMethod('setId')); } -} \ No newline at end of file +} diff --git a/tests/PathGenerator/JMSPathGeneratorTest.php b/tests/PathGenerator/JMSPathGeneratorTest.php index ff40882b..1b288fab 100644 --- a/tests/PathGenerator/JMSPathGeneratorTest.php +++ b/tests/PathGenerator/JMSPathGeneratorTest.php @@ -50,20 +50,4 @@ public function testWriter() $this->assertEquals($path, $this->tmpdir . "/Bar.yml"); } - - public function testNonExistingDir() - { - $this->setExpectedException('GoetasWebservices\Xsd\XsdToPhp\PathGenerator\PathGeneratorException'); - new Psr4PathGenerator(array( - 'myns\\' => "aaaa" - )); - } - - public function testInvalidNs() - { - $this->setExpectedException('GoetasWebservices\Xsd\XsdToPhp\PathGenerator\PathGeneratorException'); - new Psr4PathGenerator(array( - 'myns' => "aaaa" - )); - } -} \ No newline at end of file +} diff --git a/tests/PathGenerator/PHPPathGeneratorTest.php b/tests/PathGenerator/PHPPathGeneratorTest.php index 67fca543..f343cc6e 100644 --- a/tests/PathGenerator/PHPPathGeneratorTest.php +++ b/tests/PathGenerator/PHPPathGeneratorTest.php @@ -3,6 +3,7 @@ use GoetasWebservices\Xsd\XsdToPhp\Php\PathGenerator\Psr4PathGenerator; use GoetasWebservices\Xsd\XsdToPhp\Php\Structure\PHPClass; +use Zend\Code\Generator\ClassGenerator; class PHPPathGeneratorTest extends \PHPUnit_Framework_TestCase { @@ -28,7 +29,8 @@ public function testNoNs() $generator = new Psr4PathGenerator(array( 'myns\\' => $this->tmpdir )); - $generator->getPath(new PHPClass('Bar', 'myns2')); + $class = new ClassGenerator('Bar', 'myns2'); + $generator->getPath($class); } public function testWriterLong() @@ -37,7 +39,8 @@ public function testWriterLong() 'myns\\' => $this->tmpdir )); - $path = $generator->getPath(new PHPClass('Bar', 'myns\foo')); + $class = new ClassGenerator('Bar', 'myns\foo'); + $path = $generator->getPath($class); $this->assertEquals($path, $this->tmpdir . "/foo/Bar.php"); } @@ -47,25 +50,9 @@ public function testWriter() $generator = new Psr4PathGenerator(array( 'myns\\' => $this->tmpdir )); - - $path = $generator->getPath(new PHPClass('Bar', 'myns')); + $class = new ClassGenerator('Bar', 'myns'); + $path = $generator->getPath($class); $this->assertEquals($path, $this->tmpdir . "/Bar.php"); } - - public function testNonExistingDir() - { - $this->setExpectedException('GoetasWebservices\Xsd\XsdToPhp\PathGenerator\PathGeneratorException'); - new Psr4PathGenerator(array( - 'myns\\' => "aaaa" - )); - } - - public function testInvalidNs() - { - $this->setExpectedException('GoetasWebservices\Xsd\XsdToPhp\PathGenerator\PathGeneratorException'); - new Psr4PathGenerator(array( - 'myns' => "aaaa" - )); - } -} \ No newline at end of file +}