Skip to content

Commit

Permalink
create fixtures for test EventPuller service
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-gribanov committed May 24, 2021
1 parent 3c2ea0c commit 626b089
Show file tree
Hide file tree
Showing 3 changed files with 128 additions and 20 deletions.
56 changes: 56 additions & 0 deletions tests/Fixtures/SimpleObject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

/**
* GpsLab component.
*
* @author Peter Gribanov <info@peter-gribanov.ru>
* @copyright Copyright (c) 2011, Peter Gribanov
* @license http://opensource.org/licenses/MIT
*/

namespace GpsLab\Bundle\DomainEvent\Tests\Fixtures;

class SimpleObject
{
/**
* @var string
*/
private $foo;

/**
* @var string
*/
protected $camelCase = 'boo';

/**
* @return string
*/
public function getFoo()
{
return $this->foo;
}

/**
* @param string $foo
*/
public function setFoo($foo)
{
$this->foo = $foo;
}

/**
* @return string
*/
public function getCamelCase()
{
return $this->camelCase;
}

/**
* @param string $camelCase
*/
public function setCamelCase($camelCase)
{
$this->camelCase = $camelCase;
}
}
64 changes: 64 additions & 0 deletions tests/Fixtures/SimpleObjectProxy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

/**
* GpsLab component.
*
* @author Peter Gribanov <info@peter-gribanov.ru>
* @copyright Copyright (c) 2011, Peter Gribanov
* @license http://opensource.org/licenses/MIT
*/

namespace GpsLab\Bundle\DomainEvent\Tests\Fixtures;

use Doctrine\Common\Persistence\Proxy as CommonProxy;
use Doctrine\Persistence\Proxy;

if (class_exists(CommonProxy::class)) {
class SimpleObjectProxy extends SimpleObject implements CommonProxy
{
/**
* @var bool
*/
public $__isInitialized__ = false;

public function __load()
{
if (!$this->__isInitialized__) {
$this->camelCase = 'proxy-boo';
$this->__isInitialized__ = true;
}
}

/**
* @return bool
*/
public function __isInitialized()
{
return $this->__isInitialized__;
}
}
} else {
class SimpleObjectProxy extends SimpleObject implements Proxy
{
/**
* @var bool
*/
public $__isInitialized__ = false;

public function __load()
{
if (!$this->__isInitialized__) {
$this->camelCase = 'proxy-boo';
$this->__isInitialized__ = true;
}
}

/**
* @return bool
*/
public function __isInitialized()
{
return $this->__isInitialized__;
}
}
}
28 changes: 8 additions & 20 deletions tests/Service/EventPullerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

namespace GpsLab\Bundle\DomainEvent\Tests\Service;

use Doctrine\Common\Persistence\Proxy as CommonProxy;
use Doctrine\Persistence\Proxy;
use Doctrine\ORM\UnitOfWork;
use GpsLab\Bundle\DomainEvent\Service\EventPuller;
use GpsLab\Bundle\DomainEvent\Tests\Fixtures\SimpleObject;
use GpsLab\Bundle\DomainEvent\Tests\Fixtures\SimpleObjectProxy;
use GpsLab\Domain\Event\Aggregator\AggregateEvents;
use GpsLab\Domain\Event\Event;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -117,16 +117,16 @@ public function testPull(

$map = [
[
$this->getProxyMock(),
$this->getMockBuilder(SimpleObjectProxy::class)->getMock(),
$aggregator1,
],
[
$aggregator2,
new \stdClass(),
new SimpleObject(),
],
[
new \stdClass(),
$this->getProxyMock(),
new SimpleObject(),
$this->getMockBuilder(SimpleObjectProxy::class)->getMock(),
],
];
} else {
Expand Down Expand Up @@ -190,22 +190,10 @@ private function getEntitiesFroEvents(array $events)
;

return [
$this->getProxyMock(),
new \stdClass(),
$this->getMockBuilder(SimpleObjectProxy::class)->getMock(),
new SimpleObject(),
$aggregator1,
$aggregator2,
];
}

/**
* @return CommonProxy|Proxy|\PHPUnit_Framework_MockObject_MockObject
*/
private function getProxyMock()
{
if (class_exists(CommonProxy::class)) {
return $this->getMockBuilder(CommonProxy::class)->getMock();
}

return $this->getMockBuilder(Proxy::class)->getMock();
}
}

0 comments on commit 626b089

Please sign in to comment.