|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace spec\EcomDev\PHPSpec\MagentoDiAdapter; |
| 4 | + |
| 5 | +use EcomDev\PHPSpec\MagentoDiAdapter\Generator\SimplifiedDefinedClasses; |
| 6 | +use EcomDev\PHPSpec\MagentoDiAdapter\ParameterValidator; |
| 7 | +use EcomDev\PHPSpec\MagentoDiAdapter\Runner\CollaboratorMaintainer; |
| 8 | +use Magento\Framework\Code\Generator\Io; |
| 9 | +use Magento\Framework\ObjectManager\Code\Generator; |
| 10 | +use Magento\Framework\ObjectManager\Profiler\Code\Generator as ProfilerGenerator; |
| 11 | +use Magento\Framework\Api\Code\Generator\Mapper as MapperGenerator; |
| 12 | +use Magento\Framework\Api\Code\Generator\SearchResults; |
| 13 | +use org\bovigo\vfs\vfsStream; |
| 14 | +use org\bovigo\vfs\vfsStreamDirectory; |
| 15 | +use PhpSpec\Extension\ExtensionInterface; |
| 16 | +use PhpSpec\ObjectBehavior; |
| 17 | +use PhpSpec\ServiceContainer; |
| 18 | +use Prophecy\Argument; |
| 19 | + |
| 20 | +class ExtensionSpec extends ObjectBehavior |
| 21 | +{ |
| 22 | + /** |
| 23 | + * @var ServiceContainer |
| 24 | + */ |
| 25 | + private $serviceContainer; |
| 26 | + |
| 27 | + function let(ServiceContainer $serviceContainer) |
| 28 | + { |
| 29 | + $this->serviceContainer = $serviceContainer; |
| 30 | + } |
| 31 | + |
| 32 | + function it_should_implement_extension_interface() |
| 33 | + { |
| 34 | + $this->shouldImplement(ExtensionInterface::class); |
| 35 | + } |
| 36 | + |
| 37 | + function it_creates_parameter_validator_factory_with_internal_io(Io $io) |
| 38 | + { |
| 39 | + $this->serviceContainer->get('ecomdev.phpspec.magento_di_adapter.code_generator.io') |
| 40 | + ->willReturn($io); |
| 41 | + $this->serviceContainer->get('ecomdev.phpspec.magento_di_adapter.code_generator.defined_classes') |
| 42 | + ->willReturn(new SimplifiedDefinedClasses()); |
| 43 | + |
| 44 | + $validatorFactory = $this->parameterValidatorFactory(); |
| 45 | + $validatorFactory->shouldImplement(\Closure::class); |
| 46 | + $parameterValidator = $validatorFactory($this->serviceContainer); |
| 47 | + $parameterValidator->shouldImplement(ParameterValidator::class); |
| 48 | + |
| 49 | + // Test pre configured generators |
| 50 | + $parameterValidator->generator('ItemFactory') |
| 51 | + ->shouldImplement(Generator\Factory::class); |
| 52 | + $parameterValidator->generator('ItemRepository') |
| 53 | + ->shouldImplement(Generator\Repository::class); |
| 54 | + $parameterValidator->generator('ItemConverter') |
| 55 | + ->shouldImplement(Generator\Converter::class); |
| 56 | + $parameterValidator->generator('ItemPersistor') |
| 57 | + ->shouldImplement(Generator\Persistor::class); |
| 58 | + $parameterValidator->generator('ItemMapper') |
| 59 | + ->shouldImplement(MapperGenerator::class); |
| 60 | + $parameterValidator->generator('ItemSearchResults') |
| 61 | + ->shouldImplement(SearchResults::class); |
| 62 | + |
| 63 | + } |
| 64 | + |
| 65 | + function it_creates_internal_io_factory_with_vfs_stream() |
| 66 | + { |
| 67 | + $this->serviceContainer->get('ecomdev.phpspec.magento_di_adapter.vfs') |
| 68 | + ->willReturn(vfsStream::setup('custom_root_dir')); |
| 69 | + |
| 70 | + $factory = $this->ioFactory(); |
| 71 | + $factory->shouldImplement(\Closure::class); |
| 72 | + $factory($this->serviceContainer)->shouldImplement(Io::class); |
| 73 | + } |
| 74 | + |
| 75 | + function it_creates_vfs_stream_factory() |
| 76 | + { |
| 77 | + $factory = $this->vfsFactory(); |
| 78 | + $factory->shouldImplement(\Closure::class); |
| 79 | + $factory()->shouldImplement(vfsStreamDirectory::class); |
| 80 | + } |
| 81 | + |
| 82 | + |
| 83 | + function it_creates_simplified_defined_classes_factory() |
| 84 | + { |
| 85 | + $factory = $this->simplifiedDefinedClassesFactory(); |
| 86 | + $factory->shouldImplement(\Closure::class); |
| 87 | + $factory()->shouldImplement(SimplifiedDefinedClasses::class); |
| 88 | + } |
| 89 | + |
| 90 | + function it_creates_collaborator_maintainer_factory(ParameterValidator $parameterValidator) |
| 91 | + { |
| 92 | + $this->serviceContainer->get('ecomdev.phpspec.magento_di_adapter.parameter_validator') |
| 93 | + ->willReturn($parameterValidator) |
| 94 | + ->shouldBeCalled(); |
| 95 | + |
| 96 | + $factory = $this->collaboratorMaintainerFactory(); |
| 97 | + $factory->shouldImplement(\Closure::class); |
| 98 | + $factory($this->serviceContainer)->shouldImplement(CollaboratorMaintainer::class); |
| 99 | + } |
| 100 | + |
| 101 | + function it_adds_those_factories_into_container_on_load() |
| 102 | + { |
| 103 | + $this->serviceContainer |
| 104 | + ->set('ecomdev.phpspec.magento_di_adapter.code_generator.io', Argument::type(\Closure::class)) |
| 105 | + ->shouldBeCalled(); |
| 106 | + |
| 107 | + $this->serviceContainer |
| 108 | + ->set('ecomdev.phpspec.magento_di_adapter.vfs', Argument::type(\Closure::class)) |
| 109 | + ->shouldBeCalled(); |
| 110 | + |
| 111 | + $this->serviceContainer |
| 112 | + ->set('ecomdev.phpspec.magento_di_adapter.code_generator.defined_classes', Argument::type(\Closure::class)) |
| 113 | + ->shouldBeCalled(); |
| 114 | + |
| 115 | + |
| 116 | + $this->serviceContainer |
| 117 | + ->set('ecomdev.phpspec.magento_di_adapter.parameter_validator', Argument::type(\Closure::class)) |
| 118 | + ->shouldBeCalled(); |
| 119 | + |
| 120 | + $this->serviceContainer |
| 121 | + ->set('runner.maintainers.ecomdev_magento_collaborator', Argument::type(\Closure::class)) |
| 122 | + ->shouldBeCalled(); |
| 123 | + |
| 124 | + $this->load($this->serviceContainer); |
| 125 | + } |
| 126 | +} |
0 commit comments