~ubuntu-branches/ubuntu/wily/php-doctrine-common/wily-proposed

« back to all changes in this revision

Viewing changes to tests/Doctrine/Tests/Common/Persistence/ObjectManagerDecoratorTest.php

  • Committer: Package Import Robot
  • Author(s): David Prévot
  • Date: 2014-06-15 11:26:00 UTC
  • mfrom: (2.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20140615112600-sg4mgpwq9sfg4mre
Tags: 2.4.2-2
* Upload to unstable
* No tests if DEB_BUILD_OPTIONS contains nocheck

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
namespace Doctrine\Tests\Common\Persistence;
 
4
 
 
5
use Doctrine\Common\Persistence\ObjectManagerDecorator;
 
6
use Doctrine\Common\Persistence\ObjectManager;
 
7
 
 
8
class NullObjectManagerDecorator extends ObjectManagerDecorator
 
9
{
 
10
    public function __construct(ObjectManager $wrapped)
 
11
    {
 
12
        $this->wrapped = $wrapped;
 
13
    }
 
14
}
 
15
 
 
16
class ObjectManagerDecoratorTest extends \PHPUnit_Framework_TestCase
 
17
{
 
18
    private $wrapped;
 
19
    private $decorated;
 
20
 
 
21
    public function setUp()
 
22
    {
 
23
        $this->wrapped = $this->getMock('Doctrine\Common\Persistence\ObjectManager');
 
24
        $this->decorated = new NullObjectManagerDecorator($this->wrapped);
 
25
    }
 
26
 
 
27
    public function getMethodParameters()
 
28
    {
 
29
        $class = new \ReflectionClass('Doctrine\Common\Persistence\ObjectManager');
 
30
 
 
31
        $methods = array();
 
32
        foreach ($class->getMethods() as $method) {
 
33
            if ($method->getNumberOfRequiredParameters() === 0) {
 
34
               $methods[] = array($method->getName(), array());
 
35
            } elseif ($method->getNumberOfRequiredParameters() > 0) {
 
36
                $methods[] = array($method->getName(), array_fill(0, $method->getNumberOfRequiredParameters(), 'req') ?: array());
 
37
            }
 
38
            if ($method->getNumberOfParameters() != $method->getNumberOfRequiredParameters()) {
 
39
                $methods[] = array($method->getName(), array_fill(0, $method->getNumberOfParameters(), 'all') ?: array());
 
40
            }
 
41
        }
 
42
 
 
43
        return $methods;
 
44
    }
 
45
 
 
46
    /**
 
47
     * @dataProvider getMethodParameters
 
48
     */
 
49
    public function testAllMethodCallsAreDelegatedToTheWrappedInstance($method, array $parameters)
 
50
    {
 
51
        $stub = $this->wrapped
 
52
            ->expects($this->once())
 
53
            ->method($method)
 
54
            ->will($this->returnValue('INNER VALUE FROM ' . $method));
 
55
 
 
56
        call_user_func_array(array($stub, 'with'), $parameters);
 
57
 
 
58
        $this->assertSame('INNER VALUE FROM ' . $method, call_user_func_array(array($this->decorated, $method), $parameters));
 
59
    }
 
60
}
 
 
b'\\ No newline at end of file'