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 bc97af2
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 9 deletions.
40 changes: 40 additions & 0 deletions tests/Fixtures/SimpleObject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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';

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

/**
* @return string
*/
public function getFoo()
{
return $this->foo;
}
}
31 changes: 31 additions & 0 deletions tests/Fixtures/SimpleObjectCommonProxy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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;

class SimpleObjectCommonProxy extends SimpleObject implements Proxy
{
public $__isInitialized__ = false;

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

public function __isInitialized()
{
return $this->__isInitialized__;
}
}
31 changes: 31 additions & 0 deletions tests/Fixtures/SimpleObjectProxy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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\Persistence\Proxy;

class SimpleObjectProxy extends SimpleObject implements Proxy
{
public $__isInitialized__ = false;

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

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

namespace GpsLab\Bundle\DomainEvent\Tests\Service;

use Doctrine\Common\Persistence\Proxy as CommonProxy;
use Doctrine\Persistence\Proxy;
use Doctrine\Common\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\SimpleObjectCommonProxy;
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 @@ -122,10 +124,10 @@ public function testPull(
],
[
$aggregator2,
new \stdClass(),
new SimpleObject('123'),
],
[
new \stdClass(),
new SimpleObject('123'),
$this->getProxyMock(),
],
];
Expand Down Expand Up @@ -191,21 +193,21 @@ private function getEntitiesFroEvents(array $events)

return [
$this->getProxyMock(),
new \stdClass(),
new SimpleObject('123'),
$aggregator1,
$aggregator2,
];
}

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

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

0 comments on commit bc97af2

Please sign in to comment.