diff --git a/composer.json b/composer.json index fb51e61..5ef9bbb 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ "behat/behat": "^3.0.6", "behat/mink": "^1.6", "behat/mink-extension": "^2.0", - "ocramius/proxy-manager": "^1.0" + "ocramius/proxy-manager": "^1.0||^2.0" }, "require-dev": { "phpspec/phpspec": "^2.5||^3.0", diff --git a/spec/SensioLabs/Behat/PageObjectExtension/PageObject/Factory/LazyFactorySpec.php b/spec/SensioLabs/Behat/PageObjectExtension/PageObject/Factory/LazyFactorySpec.php index 271af48..67f32ef 100644 --- a/spec/SensioLabs/Behat/PageObjectExtension/PageObject/Factory/LazyFactorySpec.php +++ b/spec/SensioLabs/Behat/PageObjectExtension/PageObject/Factory/LazyFactorySpec.php @@ -2,9 +2,11 @@ namespace spec\SensioLabs\Behat\PageObjectExtension\PageObject\Factory; +require_once __DIR__.'/Fixtures/ArticleList.php'; + use PhpSpec\ObjectBehavior; use Prophecy\Argument; -use ProxyManager\Factory\AbstractLazyFactory; +use ProxyManager\Factory\LazyLoadingValueHolderFactory; use ProxyManager\Proxy\LazyLoadingInterface; use SensioLabs\Behat\PageObjectExtension\PageObject\Element; use SensioLabs\Behat\PageObjectExtension\PageObject\Factory; @@ -14,9 +16,9 @@ class LazyFactorySpec extends ObjectBehavior { - function let(Factory $decoratedFactory, AbstractLazyFactory $proxyFactory) + function let(Factory $decoratedFactory) { - $this->beConstructedWith($decoratedFactory, $proxyFactory); + $this->beConstructedWith($decoratedFactory, new LazyLoadingValueHolderFactory()); } function it_is_a_page_object_factory() @@ -26,9 +28,9 @@ function it_is_a_page_object_factory() function it_delegates_create_page_calls_to_the_decorated_factory(Factory $decoratedFactory, Page $page) { - $decoratedFactory->createPage('Foo')->willReturn($page); + $decoratedFactory->createPage('ArticleList')->willReturn($page); - $this->createPage('Foo')->shouldReturn($page); + $this->createPage('ArticleList')->shouldReturn($page); } function it_delegates_create_element_calls_to_the_decorated_factory(Factory $decoratedFactory, Element $element) @@ -45,37 +47,15 @@ function it_delegates_create_inline_element_calls_to_the_decorated_factory(Facto $this->createInlineElement('.foo')->shouldReturn($element); } - function it_creates_a_proxy_instead_of_instantiating_a_page_object_right_away(AbstractLazyFactory $proxyFactory, LazyLoadingInterface $proxy) + function it_creates_a_proxy_instead_of_instantiating_a_page_object_right_away() { - $proxyFactory->createProxy('Acme\Page', Argument::type('Closure'))->willReturn($proxy); - - $this->create('Acme\Page')->shouldReturn($proxy); + $this->create('ArticleList')->shouldReturnAnInstanceOf('ProxyManager\Proxy\LazyLoadingInterface'); } - function it_delegates_instantiation_to_the_decorated_factory(AbstractLazyFactory $proxyFactory, LazyLoadingInterface $proxy, PageObject $pageObject, Factory $decoratedFactory) + function it_delegates_instantiation_to_the_decorated_factory(PageObject $pageObject, Factory $decoratedFactory) { - $decoratedFactory->create('Acme\Page')->willReturn($pageObject); - - $proxyFactory->createProxy( - Argument::any(), - Argument::that(function ($callback) use ($proxy, $pageObject) { - $wrappedObject = new \stdClass(); - $initializer = function () {}; - - $result = $callback($wrappedObject, $proxy->getWrappedObject(), null, array(), $initializer); - - if ($wrappedObject !== $pageObject->getWrappedObject()) { - throw new \LogicException('Expected the proxy to be overwritten with the actual object'); - } - - if (null !== $initializer) { - throw new \LogicException('Expected the initializer callback to be set to null'); - } - - return $result; - }) - )->shouldBeCalled(); + $decoratedFactory->create('ArticleList')->willReturn($pageObject); - $this->create('Acme\Page'); + $this->create('ArticleList')->shouldReturnAnInstanceOf('ProxyManager\Proxy\ProxyInterface'); } } diff --git a/src/SensioLabs/Behat/PageObjectExtension/PageObject/Factory/LazyFactory.php b/src/SensioLabs/Behat/PageObjectExtension/PageObject/Factory/LazyFactory.php index 2d8261d..bae4719 100644 --- a/src/SensioLabs/Behat/PageObjectExtension/PageObject/Factory/LazyFactory.php +++ b/src/SensioLabs/Behat/PageObjectExtension/PageObject/Factory/LazyFactory.php @@ -2,7 +2,7 @@ namespace SensioLabs\Behat\PageObjectExtension\PageObject\Factory; -use ProxyManager\Factory\AbstractLazyFactory; +use ProxyManager\Factory\LazyLoadingValueHolderFactory; use ProxyManager\Proxy\LazyLoadingInterface; use SensioLabs\Behat\PageObjectExtension\PageObject\Element; use SensioLabs\Behat\PageObjectExtension\PageObject\Factory; @@ -18,15 +18,15 @@ class LazyFactory implements Factory private $decoratedFactory; /** - * @var AbstractLazyFactory + * @var LazyLoadingValueHolderFactory */ private $proxyFactory; /** - * @param Factory $decoratedFactory - * @param AbstractLazyFactory $proxyFactory + * @param Factory $decoratedFactory + * @param LazyLoadingValueHolderFactory $proxyFactory */ - public function __construct(Factory $decoratedFactory, AbstractLazyFactory $proxyFactory) + public function __construct(Factory $decoratedFactory, LazyLoadingValueHolderFactory $proxyFactory) { $this->decoratedFactory = $decoratedFactory; $this->proxyFactory = $proxyFactory; diff --git a/src/SensioLabs/Behat/PageObjectExtension/ServiceContainer/config/services.xml b/src/SensioLabs/Behat/PageObjectExtension/ServiceContainer/config/services.xml index 6ba46e6..117e7b9 100644 --- a/src/SensioLabs/Behat/PageObjectExtension/ServiceContainer/config/services.xml +++ b/src/SensioLabs/Behat/PageObjectExtension/ServiceContainer/config/services.xml @@ -32,6 +32,17 @@ %sensio_labs.page_object_extension.proxies_target_dir% + + + + + + %sensio_labs.page_object_extension.proxies_target_dir% + + + + +