1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the LoopBackApiBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) Théo FIDRY <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Fidry\LoopBackApiBundle\Tests\Prophecy; |
13
|
|
|
|
14
|
|
|
use Prophecy\Argument; |
15
|
|
|
use Symfony\Component\Config\Resource\FileResource; |
16
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Extends {@see \Prophecy\Argument}. |
20
|
|
|
* |
21
|
|
|
* @author Théo FIDRY <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class DependencyInjectionArgument |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Checks that the argument passed is an instance of Definition for the given class. |
27
|
|
|
* |
28
|
|
|
* @param string $class FQCN |
29
|
|
|
* |
30
|
|
|
* @return \Prophecy\Argument\Token\CallbackToken |
31
|
|
|
*/ |
32
|
|
|
public static function definition($class) |
33
|
|
|
{ |
34
|
|
|
return Argument::that(function ($args) use ($class) { |
35
|
|
|
/** @var Definition $args */ |
36
|
|
|
if (false === $args instanceof Definition) { |
37
|
|
|
return false; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
$service = (new \ReflectionClass($args->getClass()))->newInstanceWithoutConstructor(); |
41
|
|
|
|
42
|
|
|
return $service instanceof $class; |
43
|
|
|
}); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Checks that the argument passed is an instance of FileResource with the given resource. |
48
|
|
|
* |
49
|
|
|
* @param string $filePath |
50
|
|
|
* |
51
|
|
|
* @return \Prophecy\Argument\Token\CallbackToken |
52
|
|
|
*/ |
53
|
|
|
public static function service($filePath) |
54
|
|
|
{ |
55
|
|
|
return Argument::that(function ($args) use ($filePath) { |
56
|
|
|
/** @var FileResource $args */ |
57
|
|
|
if (false === $args instanceof FileResource) { |
58
|
|
|
return false; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return $filePath === $args->getResource(); |
62
|
|
|
}); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|