Skip to content

Commit 459534f

Browse files
committed
Fix tests
1 parent e22c987 commit 459534f

55 files changed

Lines changed: 769 additions & 350 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

spec/Phpro/SoapClient/CodeGenerator/ClassMapGeneratorSpec.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
namespace spec\Phpro\SoapClient\CodeGenerator;
44

55
use Phpro\SoapClient\CodeGenerator\ClassMapGenerator;
6+
use Phpro\SoapClient\CodeGenerator\Config\ClassMapConfig;
7+
use Phpro\SoapClient\CodeGenerator\Config\Destination;
8+
use Phpro\SoapClient\CodeGenerator\Config\TypeNamespaceMap;
69
use Phpro\SoapClient\CodeGenerator\Context\ClassMapContext;
710
use Phpro\SoapClient\CodeGenerator\Context\FileContext;
811
use Phpro\SoapClient\CodeGenerator\GeneratorInterface;
@@ -11,6 +14,7 @@
1114
use PhpSpec\ObjectBehavior;
1215
use Prophecy\Argument;
1316
use Laminas\Code\Generator\FileGenerator;
17+
use Soap\Engine\Metadata\Collection\TypeCollection;
1418

1519
/**
1620
* Class ClassMapGeneratorSpec
@@ -22,7 +26,8 @@ class ClassMapGeneratorSpec extends ObjectBehavior
2226
{
2327
function let(RuleSetInterface $ruleSet)
2428
{
25-
$this->beConstructedWith($ruleSet, 'ClassMap', 'App\\Mynamespace');
29+
$classMapConfig = new ClassMapConfig('ClassMap', new Destination('/app', 'App\\Mynamespace'));
30+
$this->beConstructedWith($ruleSet, $classMapConfig);
2631
}
2732

2833
function it_is_initializable()
@@ -35,11 +40,14 @@ function it_is_a_generator()
3540
$this->shouldImplement(GeneratorInterface::class);
3641
}
3742

38-
function it_generates_classmaps(RuleSetInterface $ruleSet, FileGenerator $file, TypeMap $typeMap)
43+
function it_generates_classmaps(RuleSetInterface $ruleSet, FileGenerator $file)
3944
{
4045
$ruleSet->applyRules(Argument::type(ClassMapContext::class))->shouldBeCalled();
4146
$ruleSet->applyRules(Argument::type(FileContext::class))->shouldBeCalled();
4247
$file->generate()->willReturn('code');
43-
$this->generate($file, $typeMap)->shouldReturn('code');
48+
$this->generate($file, TypeMap::fromMetadata(
49+
TypeNamespaceMap::create(new Destination('/app', 'App\\Mynamespace')),
50+
new TypeCollection(),
51+
))->shouldReturn('code');
4452
}
4553
}

spec/Phpro/SoapClient/CodeGenerator/ClientGeneratorSpec.php

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
use Laminas\Code\Generator\Exception\ClassNotFoundException;
66
use Phpro\SoapClient\CodeGenerator\ClassMapGenerator;
77
use Phpro\SoapClient\CodeGenerator\ClientGenerator;
8+
use Phpro\SoapClient\CodeGenerator\Config\ClientConfig;
9+
use Phpro\SoapClient\CodeGenerator\Config\Destination;
10+
use Phpro\SoapClient\CodeGenerator\Config\TypeNamespaceMap;
811
use Phpro\SoapClient\CodeGenerator\Context\ClientContext;
912
use Phpro\SoapClient\CodeGenerator\Context\ClientMethodContext;
1013
use Phpro\SoapClient\CodeGenerator\Context\FileContext;
@@ -46,13 +49,14 @@ function it_is_a_generator()
4649
$this->shouldImplement(GeneratorInterface::class);
4750
}
4851

49-
function it_generates_clients(RuleSetInterface $ruleSet, FileGenerator $file, Client $client, ClientMethodMap $map, ClassGenerator $class)
52+
function it_generates_clients(RuleSetInterface $ruleSet, FileGenerator $file, ClassGenerator $class)
5053
{
54+
$typeNamespaceMap = TypeNamespaceMap::create(new Destination('/app', ''));
5155
$method = new ClientMethod(
5256
'Test',
53-
[new Parameter('parameters', 'Test', '', XsdType::create('Test'))],
54-
ReturnType::fromMetaData('', XsdType::create('TestResponse')),
55-
'',
57+
[new Parameter('parameters', 'Test', $typeNamespaceMap, XsdType::create('Test'))],
58+
ReturnType::fromMetaData($typeNamespaceMap, XsdType::create('TestResponse')),
59+
$typeNamespaceMap,
5660
new MethodMeta()
5761
);
5862
$ruleSet->applyRules(Argument::type(ClientMethodContext::class))->shouldBeCalled();
@@ -63,33 +67,35 @@ function it_generates_clients(RuleSetInterface $ruleSet, FileGenerator $file, Cl
6367
$file->getClass()->willThrow(new ClassNotFoundException('No class is set'));
6468
$file->setClass(Argument::type(ClassGenerator::class))->shouldBeCalled();
6569

66-
$client->getMethodMap()->willReturn($map);
67-
$map->getMethods()->willReturn([$method]);
68-
$client->getNamespace()->willReturn('MyNamespace');
69-
$client->getName()->willReturn('MyClient');
70+
$client = new Client(
71+
new ClientConfig('MyClient', new Destination('', 'MyNamespace')),
72+
new ClientMethodMap([$method])
73+
);
7074
$this->generate($file, $client)->shouldReturn('code');
7175
}
7276

73-
private function it_generates_clients_for_file_without_classes(RuleSetInterface $ruleSet, FileGenerator $file, Client $client, ClientMethodMap $map, ClassGenerator $class)
77+
function it_generates_clients_for_file_without_classes(RuleSetInterface $ruleSet, FileGenerator $file, ClassGenerator $class)
7478
{
79+
$typeNamespaceMap = TypeNamespaceMap::create(new Destination('/app', ''));
7580
$method = new ClientMethod(
7681
'Test',
77-
[new Parameter('parameters', 'Test', '', XsdType::create('Test'))],
78-
ReturnType::fromMetaData('', XsdType::create('TestResponse')),
79-
'',
82+
[new Parameter('parameters', 'Test', $typeNamespaceMap, XsdType::create('Test'))],
83+
ReturnType::fromMetaData($typeNamespaceMap, XsdType::create('TestResponse')),
84+
$typeNamespaceMap,
8085
new MethodMeta()
8186
);
8287

8388
$ruleSet->applyRules(Argument::type(ClientMethodContext::class))->shouldBeCalled();
89+
$ruleSet->applyRules(Argument::type(ClientContext::class))->shouldBeCalled();
90+
$ruleSet->applyRules(Argument::type(FileContext::class))->shouldBeCalled();
8491
$file->generate()->willReturn('code');
8592

8693
$file->getClass()->willReturn($class);
8794
$file->setClass($class)->shouldBeCalled();
88-
89-
$client->getMethodMap()->willReturn($map);
90-
$map->getMethods()->willReturn([$method]);
91-
$client->getNamespace()->willReturn('MyNamespace');
92-
$client->getName()->willReturn('MyClient');
95+
$client = new Client(
96+
new ClientConfig('MyClient', new Destination('', 'MyNamespace')),
97+
new ClientMethodMap([$method])
98+
);
9399
$this->generate($file, $client)->shouldReturn('code');
94100
}
95101
}

spec/Phpro/SoapClient/CodeGenerator/Config/ConfigSpec.php

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
namespace spec\Phpro\SoapClient\CodeGenerator\Config;
44

5+
use Phpro\SoapClient\CodeGenerator\Config\ClientConfig;
6+
use Phpro\SoapClient\CodeGenerator\Config\ClassMapConfig;
57
use Phpro\SoapClient\CodeGenerator\Config\Config;
6-
use Phpro\SoapClient\CodeGenerator\Config\ConfigInterface;
8+
use Phpro\SoapClient\CodeGenerator\Config\Destination;
9+
use Phpro\SoapClient\CodeGenerator\Config\TypeNamespaceMap;
710
use Phpro\SoapClient\CodeGenerator\Rules\RuleSet;
811
use Phpro\SoapClient\Exception\InvalidArgumentException;
9-
use Phpro\SoapClient\Util\Filesystem;
1012
use PhpSpec\ObjectBehavior;
1113
use Soap\Engine\Engine;
1214

@@ -34,9 +36,9 @@ function it_requires_an_engine()
3436
$this->shouldThrow(InvalidArgumentException::class)->duringGetEngine();
3537
}
3638

37-
function it_requires_a_typedestination()
39+
function it_requires_a_type_namespace_map()
3840
{
39-
$this->shouldThrow(InvalidArgumentException::class)->duringGetTypeDestination();
41+
$this->shouldThrow(InvalidArgumentException::class)->duringGetTypeNamespaceMap();
4042
}
4143

4244
function it_has_a_ruleset()
@@ -45,38 +47,37 @@ function it_has_a_ruleset()
4547
$this->getRuleSet()->shouldBe($value);
4648
}
4749

48-
public function it_has_a_type_destination()
50+
public function it_has_a_type_namespace_map()
4951
{
50-
$this->setTypeDestination($value = 'src/type');
51-
$this->getTypeDestination()->shouldBe($value);
52+
$destination = new Destination('src/type', 'TypeNamespace');
53+
$value = TypeNamespaceMap::create($destination);
54+
$this->setTypeNamespaceMap($value);
55+
$this->getTypeNamespaceMap()->shouldBe($value);
5256
}
5357

54-
public function it_has_a_client_destination()
58+
public function it_has_a_client_config()
5559
{
56-
$this->setClientDestination($value = 'src/client');
57-
$this->getClientDestination()->shouldBe($value);
60+
$destination = new Destination('src/client', 'ClientNamespace');
61+
$value = new ClientConfig('ClientName', $destination);
62+
$this->setClient($value);
63+
$this->getClient()->shouldBe($value);
5864
}
5965

60-
public function it_has_a_type_namespace()
66+
public function it_requires_a_client_config()
6167
{
62-
$this->setTypeNamespace($value = 'TypeNamespace');
63-
$this->getTypeNamespace()->shouldBe($value);
68+
$this->shouldThrow(InvalidArgumentException::class)->duringGetClient();
6469
}
6570

66-
public function it_has_a_client_namespace()
71+
public function it_has_a_classmap_config()
6772
{
68-
$this->setClientNamespace($value = 'ClientNamespace');
69-
$this->getClientNamespace()->shouldBe($value);
73+
$destination = new Destination('src/classmap', 'ClassMapNamespace');
74+
$value = new ClassMapConfig('ClassMapName', $destination);
75+
$this->setClassMap($value);
76+
$this->getClassMap()->shouldBe($value);
7077
}
7178

72-
public function it_requires_a_client_namespace()
79+
public function it_requires_a_classmap_config()
7380
{
74-
$this->shouldThrow(InvalidArgumentException::class)->duringGetClientNamespace();
75-
}
76-
77-
public function it_has_a_client_name()
78-
{
79-
$this->setClientName($value = 'ClientName');
80-
$this->getClientName()->shouldBe($value);
81+
$this->shouldThrow(InvalidArgumentException::class)->duringGetClassMap();
8182
}
8283
}

spec/Phpro/SoapClient/CodeGenerator/Context/ClassMapContextSpec.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22

33
namespace spec\Phpro\SoapClient\CodeGenerator\Context;
44

5+
use Phpro\SoapClient\CodeGenerator\Config\ClassMapConfig;
6+
use Phpro\SoapClient\CodeGenerator\Config\Destination;
7+
use Phpro\SoapClient\CodeGenerator\Config\TypeNamespaceMap;
58
use Phpro\SoapClient\CodeGenerator\Context\ClassMapContext;
69
use Phpro\SoapClient\CodeGenerator\Context\ContextInterface;
710
use Phpro\SoapClient\CodeGenerator\Model\TypeMap;
811
use PhpSpec\ObjectBehavior;
9-
use Prophecy\Argument;
1012
use Laminas\Code\Generator\FileGenerator;
1113

1214
/**
@@ -17,16 +19,25 @@
1719
*/
1820
class ClassMapContextSpec extends ObjectBehavior
1921
{
20-
function let(FileGenerator $fileGenerator, TypeMap $typeMap)
22+
private TypeMap $typeMap;
23+
24+
function let(FileGenerator $fileGenerator)
2125
{
22-
$this->beConstructedWith($fileGenerator, $typeMap, 'ClassMap', 'App\\Mynamespace');
26+
$typeDestination = new Destination('src/type', 'App\\Mynamespace');
27+
$namespaceMap = TypeNamespaceMap::create($typeDestination);
28+
$this->typeMap = new TypeMap($namespaceMap, []);
29+
30+
$classMapDestination = new Destination('src/classmap', 'App\\Mynamespace');
31+
$classMapConfig = new ClassMapConfig('ClassMap', $classMapDestination);
32+
33+
$this->beConstructedWith($fileGenerator, $this->typeMap, $classMapConfig);
2334
}
2435

2536
function it_is_initializable()
2637
{
2738
$this->shouldHaveType(ClassMapContext::class);
2839
}
29-
40+
3041
function it_is_a_context()
3142
{
3243
$this->shouldImplement(ContextInterface::class);
@@ -37,8 +48,8 @@ function it_has_a_file_generator(FileGenerator $fileGenerator)
3748
$this->getFile()->shouldReturn($fileGenerator);
3849
}
3950

40-
function it_has_a_typemap(TypeMap $typeMap)
51+
function it_has_a_typemap()
4152
{
42-
$this->getTypeMap()->shouldReturn($typeMap);
53+
$this->getTypeMap()->shouldReturn($this->typeMap);
4354
}
4455
}

spec/Phpro/SoapClient/CodeGenerator/Context/ClientContextSpec.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,24 @@
33
namespace spec\Phpro\SoapClient\CodeGenerator\Context;
44

55
use Laminas\Code\Generator\ClassGenerator;
6+
use Phpro\SoapClient\CodeGenerator\Config\ClientConfig;
7+
use Phpro\SoapClient\CodeGenerator\Config\Destination;
68
use Phpro\SoapClient\CodeGenerator\Context\ClientContext;
7-
use Phpro\SoapClient\CodeGenerator\Context\TypeContext;
89
use PhpSpec\ObjectBehavior;
910

1011
/**
11-
* Class TypeContextSpec
12+
* Class ClientContextSpec
1213
*
1314
* @package spec\Phpro\SoapClient\CodeGenerator\Context
14-
* @mixin TypeContext
15+
* @mixin ClientContext
1516
*/
1617
class ClientContextSpec extends ObjectBehavior
1718
{
1819
function let(ClassGenerator $class)
1920
{
20-
$this->beConstructedWith($class, 'MyClient', 'App\Client');
21+
$destination = new Destination('src/client', 'App\Client');
22+
$clientConfig = new ClientConfig('MyClient', $destination);
23+
$this->beConstructedWith($class, $clientConfig);
2124
}
2225

2326
function it_is_initializable()

spec/Phpro/SoapClient/CodeGenerator/Context/ClientFactoryContextSpec.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
namespace spec\Phpro\SoapClient\CodeGenerator\Context;
44

55
use Laminas\Code\Generator\ClassGenerator;
6-
use Phpro\SoapClient\CodeGenerator\Config\Config;
6+
use Phpro\SoapClient\CodeGenerator\Config\ClientConfig;
7+
use Phpro\SoapClient\CodeGenerator\Config\ClassMapConfig;
8+
use Phpro\SoapClient\CodeGenerator\Config\Destination;
79
use Phpro\SoapClient\CodeGenerator\Context\ClassMapContext;
810
use Phpro\SoapClient\CodeGenerator\Context\ClientContext;
911
use Phpro\SoapClient\CodeGenerator\Context\ContextInterface;
1012
use Phpro\SoapClient\CodeGenerator\Model\TypeMap;
1113
use PhpSpec\ObjectBehavior;
12-
use Prophecy\Argument;
1314
use Phpro\SoapClient\CodeGenerator\Context\ClientFactoryContext;
1415
use Laminas\Code\Generator\FileGenerator;
1516

@@ -20,12 +21,18 @@ class ClientFactoryContextSpec extends ObjectBehavior
2021
{
2122
function let()
2223
{
23-
$clientContext = new ClientContext(new ClassGenerator(), 'Myclient', 'App\\Client');
24+
$clientDestination = new Destination('src/client', 'App\\Client');
25+
$clientConfig = new ClientConfig('Myclient', $clientDestination);
26+
$clientContext = new ClientContext(new ClassGenerator(), $clientConfig);
27+
28+
$classMapDestination = new Destination('src/classmap', 'App\\Classmap');
29+
$typeDestination = new Destination('src/type', 'ns');
30+
$namespaceMap = \Phpro\SoapClient\CodeGenerator\Config\TypeNamespaceMap::create($typeDestination);
31+
$classMapConfig = new ClassMapConfig('Myclassmap', $classMapDestination);
2432
$classMapContext = new ClassMapContext(
2533
new FileGenerator(),
26-
new TypeMap('ns', []),
27-
'Myclassmap',
28-
'App\\Classmap'
34+
new TypeMap($namespaceMap, []),
35+
$classMapConfig
2936
);
3037
$this->beConstructedWith($clientContext, $classMapContext);
3138
}

spec/Phpro/SoapClient/CodeGenerator/Context/ClientMethodContextSpec.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,41 @@
22

33
namespace spec\Phpro\SoapClient\CodeGenerator\Context;
44

5+
use Phpro\SoapClient\CodeGenerator\Config\Destination;
6+
use Phpro\SoapClient\CodeGenerator\Config\TypeNamespaceMap;
57
use Phpro\SoapClient\CodeGenerator\Context\ContextInterface;
68
use Phpro\SoapClient\CodeGenerator\Context\ClientMethodContext;
7-
use Phpro\SoapClient\CodeGenerator\Context\TypeContext;
89
use Phpro\SoapClient\CodeGenerator\Model\ClientMethod;
10+
use Phpro\SoapClient\CodeGenerator\Model\ReturnType;
911
use PhpSpec\ObjectBehavior;
1012
use Laminas\Code\Generator\ClassGenerator;
13+
use Soap\Engine\Metadata\Model\MethodMeta;
14+
use Soap\Engine\Metadata\Model\XsdType;
1115

1216
/**
1317
* Class ClientMethodContextSpec
1418
*
1519
* @package spec\Phpro\SoapClient\CodeGenerator\Context
16-
* @mixin TypeContext
20+
* @mixin ClientMethodContext
1721
*/
1822
class ClientMethodContextSpec extends ObjectBehavior
1923
{
20-
function let(ClassGenerator $class, ClientMethod $method)
24+
private ClientMethod $method;
25+
26+
function let(ClassGenerator $class)
2127
{
22-
$this->beConstructedWith($class, $method);
28+
$destination = new Destination('src/type', 'ParamNamespace');
29+
$namespaceMap = TypeNamespaceMap::create($destination);
30+
31+
$this->method = new ClientMethod(
32+
'testMethod',
33+
[],
34+
ReturnType::fromMetaData($namespaceMap, XsdType::create('CreditResponse')),
35+
$namespaceMap,
36+
new MethodMeta()
37+
);
38+
39+
$this->beConstructedWith($class, $this->method);
2340
}
2441

2542
function it_is_initializable()
@@ -37,8 +54,8 @@ function it_has_a_class_generator(ClassGenerator $class)
3754
$this->getClass()->shouldReturn($class);
3855
}
3956

40-
function it_has_a_method(ClientMethod $method)
57+
function it_has_a_method()
4158
{
42-
$this->getMethod()->shouldReturn($method);
59+
$this->getMethod()->shouldReturn($this->method);
4360
}
4461
}

0 commit comments

Comments
 (0)