Completed
Pull Request — develop (#693)
by Tom
11:30
created

ObjectExistsFactoryTest::testInvoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 9.52
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DoctrineModule\Validator\Service;
6
7
use PHPUnit\Framework\TestCase;
8
use DoctrineModule\Validator\ObjectExists;
9
use Doctrine\Persistence\ObjectManager;
10
use Doctrine\Persistence\ObjectRepository;
11
use Interop\Container\ContainerInterface;
12
use PHPUnit\Framework\TestCase;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Cannot use PHPUnit\Framework\TestCase as TestCase because the name is already in use
Loading history...
13
14
/**
15
 * Generated by PHPUnit_SkeletonGenerator on 2017-09-04 at 11:55:36.
16
 *
17
 * @coversDefaultClass DoctrineModule\Validator\Service\ObjectExistsFactory
18
 * @group validator
19
 */
20
class ObjectExistsFactoryTest extends TestCase
21
{
22
    /** @var ObjectExistsFactory */
23
    protected $object;
24
25
    /**
26
     * Sets up the fixture, for example, opens a network connection.
27
     * This method is called before a test is executed.
28
     */
29
    protected function setUp() : void
30
    {
31
        $this->object = new ObjectExistsFactory();
32
    }
33
34
    /**
35
     * @covers ::__invoke
36
     */
37
    public function testInvoke() : void
38
    {
39
        $options = [
40
            'target_class' => 'Foo\Bar',
41
            'fields'       => ['test'],
42
        ];
43
44
        $repository    = $this->prophesize(ObjectRepository::class);
45
        $objectManager = $this->prophesize(ObjectManager::class);
46
        $objectManager->getRepository('Foo\Bar')
47
            ->shouldBeCalled()
48
            ->willReturn($repository->reveal());
49
50
        $container = $this->prophesize(ContainerInterface::class);
51
        $container->get('doctrine.entitymanager.orm_default')
52
            ->shouldBeCalled()
53
            ->willReturn($objectManager->reveal());
54
55
        $instance = $this->object->__invoke(
56
            $container->reveal(),
57
            ObjectExists::class,
58
            $options
59
        );
60
        $this->assertInstanceOf(ObjectExists::class, $instance);
61
    }
62
}
63