Skip to content

Commit

Permalink
Allow both v1 and v2 of the proxy-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
jakzal committed Jan 18, 2017
1 parent 02414dd commit 507a85f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 38 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand All @@ -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)
Expand All @@ -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');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@
<argument type="service">
<service class="ProxyManager\Configuration">
<call method="setProxiesTargetDir"><argument>%sensio_labs.page_object_extension.proxies_target_dir%</argument></call>
<call method="setGeneratorStrategy">
<argument type="service">
<service class="ProxyManager\GeneratorStrategy\FileWriterGeneratorStrategy">
<argument type="service">
<service class="ProxyManager\FileLocator\FileLocator">
<argument>%sensio_labs.page_object_extension.proxies_target_dir%</argument>
</service>
</argument>
</service>
</argument>
</call>
</service>
</argument>
</service>
Expand Down

0 comments on commit 507a85f

Please sign in to comment.