These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Kunstmaan\NodeSearchBundle\Tests\unit\Services; |
||
4 | |||
5 | use Elastica\Query; |
||
6 | use Kunstmaan\NodeSearchBundle\Entity\AbstractSearchPage; |
||
7 | use Kunstmaan\NodeSearchBundle\Search\AbstractElasticaSearcher; |
||
8 | use Kunstmaan\NodeSearchBundle\Services\SearchService; |
||
9 | use PHPUnit\Framework\TestCase; |
||
10 | use Symfony\Component\DependencyInjection\ContainerInterface; |
||
11 | use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; |
||
12 | use Symfony\Component\HttpFoundation\ParameterBag; |
||
13 | use Symfony\Component\HttpFoundation\Request; |
||
14 | use Symfony\Component\HttpFoundation\RequestStack; |
||
15 | |||
16 | class SearchServiceTest extends TestCase |
||
17 | { |
||
18 | /** |
||
19 | * @group legacy |
||
20 | * @expectedDeprecation Getting the node searcher "%s" from the container is deprecated in KunstmaanNodeSearchBundle 5.2 and will be removed in KunstmaanNodeSearchBundle 6.0. Tag your searcher service with the "kunstmaan_node_search.node_searcher" tag to add a searcher. |
||
21 | */ |
||
22 | public function testLegacyContainerSearcher() |
||
23 | { |
||
24 | $entity = new AbstractSearchPage(); |
||
25 | $parameterBag = new ParameterBag(); |
||
26 | $parameterBag->add([ |
||
27 | '_entity' => $entity, |
||
28 | 'query' => '', |
||
29 | 'type' => 'html/text', |
||
30 | ]); |
||
31 | |||
32 | $request = $this->createMock(Request::class); |
||
33 | $request->attributes = $parameterBag; |
||
0 ignored issues
–
show
|
|||
34 | $request->query = $parameterBag; |
||
0 ignored issues
–
show
Accessing
query on the interface PHPUnit\Framework\MockObject\MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
Loading history...
|
|||
35 | |||
36 | $elasticSearcher = $this->createMock(AbstractElasticaSearcher::class); |
||
37 | $elasticSearcher->method('setData')->willReturnSelf(); |
||
38 | $elasticSearcher->method('setContentType')->willReturnSelf(); |
||
39 | $elasticSearcher->method('getQuery')->willReturn(new Query()); |
||
40 | |||
41 | $container = $this->createMock(ContainerInterface::class); |
||
42 | $container->method('get')->with('kunstmaan_node_search.search.node')->willReturn($elasticSearcher); |
||
43 | |||
44 | $requestStack = $this->createMock(RequestStack::class); |
||
45 | $requestStack->method('getCurrentRequest')->willReturn($request); |
||
46 | |||
47 | $searcher = new SearchService($container, $requestStack, 10, []); |
||
0 ignored issues
–
show
$container is of type object<PHPUnit\Framework\MockObject\MockObject> , but the function expects a object<Symfony\Component...ion\ContainerInterface> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
$requestStack is of type object<PHPUnit\Framework\MockObject\MockObject> , but the function expects a object<Symfony\Component...oundation\RequestStack> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
48 | |||
49 | $searcher->search(); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException |
||
54 | */ |
||
55 | public function testUnknownSearcher() |
||
56 | { |
||
57 | $entity = $this->createMock(AbstractSearchPage::class); |
||
58 | $entity->method('getSearcher')->willReturn('unknown_searcher'); |
||
59 | |||
60 | $parameterBag = new ParameterBag(); |
||
61 | $parameterBag->set('_entity', $entity); |
||
62 | |||
63 | $request = $this->createMock(Request::class); |
||
64 | $request->attributes = $parameterBag; |
||
0 ignored issues
–
show
Accessing
attributes on the interface PHPUnit\Framework\MockObject\MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
Loading history...
|
|||
65 | $request->query = $parameterBag; |
||
0 ignored issues
–
show
Accessing
query on the interface PHPUnit\Framework\MockObject\MockObject suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
Loading history...
|
|||
66 | |||
67 | $container = $this->createMock(ContainerInterface::class); |
||
68 | $container->method('get')->with('unknown_searcher')->willThrowException(new ServiceNotFoundException('unknown_searcher')); |
||
69 | |||
70 | $requestStack = $this->createMock(RequestStack::class); |
||
71 | $requestStack->method('getCurrentRequest')->willReturn($request); |
||
72 | |||
73 | $searcher = new SearchService($container, $requestStack, 10, []); |
||
0 ignored issues
–
show
$container is of type object<PHPUnit\Framework\MockObject\MockObject> , but the function expects a object<Symfony\Component...ion\ContainerInterface> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
$requestStack is of type object<PHPUnit\Framework\MockObject\MockObject> , but the function expects a object<Symfony\Component...oundation\RequestStack> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
74 | |||
75 | $searcher->search(); |
||
76 | } |
||
77 | } |
||
78 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: