GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( a111ac...84e69f )
by Florian
03:10
created

DummySearchServiceTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 2
Bugs 1 Features 2
Metric Value
c 2
b 1
f 2
dl 0
loc 96
wmc 9
lcom 1
cbo 7
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A getSearchService() 0 5 1
A indexBeer() 0 13 1
A testSaveDocument() 0 6 1
A testSaveDocumentComposite() 0 15 1
A testRemoveDocument() 0 7 1
A testAutocompletion() 0 8 1
A testSearch() 0 5 1
A getUsedEntityFixtures() 0 6 1
1
<?php
2
3
/*
4
 * This file is part of the Stinger Enity Search package.
5
 *
6
 * (c) Oliver Kotte <[email protected]>
7
 * (c) Florian Meyer <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
namespace StingerSoft\EntitySearchBundle\Tests\Services;
13
14
use StingerSoft\EntitySearchBundle\Services\DummySearchService;
15
use StingerSoft\EntitySearchBundle\Tests\AbstractORMTestCase;
16
use StingerSoft\EntitySearchBundle\Tests\Fixtures\ORM\Beer;
17
use StingerSoft\EntitySearchBundle\Tests\Fixtures\ORM\Car;
18
use StingerSoft\EntitySearchBundle\Services\SearchService;
19
use StingerSoft\EntitySearchBundle\Model\Query;
20
21
class DummySearchServiceTest extends AbstractORMTestCase {
22
23
	/**
24
	 *
25
	 * {@inheritDoc}
26
	 *
27
	 * @see PHPUnit_Framework_TestCase::setUp()
28
	 */
29
	public function setUp() {
30
		parent::setUp();
31
		$this->getMockSqliteEntityManager();
32
	}
33
34
	/**
35
	 *
36
	 * @return \StingerSoft\EntitySearchBundle\Services\DummySearchService
37
	 */
38
	protected function getSearchService() {
39
		$service = new DummySearchService();
40
		$service->setObjectManager($this->em);
41
		return $service;
42
	}
43
44
	protected function indexBeer(SearchService $service) {
45
		$beer = new Beer();
46
		$beer->setTitle('Hemelinger');
47
		$this->em->persist($beer);
48
		$this->em->flush();
49
		
50
		$document = $service->createEmptyDocumentFromEntity($beer);
51
		$this->assertAttributeCount(0, 'index', $service);
52
		$beer->indexEntity($document);
53
		$service->saveDocument($document);
54
		$this->assertAttributeCount(1, 'index', $service);
55
		return array($beer, $document);
56
	}
57
58
	public function testSaveDocument() {
59
		$service = $this->getSearchService();
60
		$this->indexBeer($service);
61
		$service->clearIndex();
62
		$this->assertAttributeCount(0, 'index', $service);
63
	}
64
65
	public function testSaveDocumentComposite() {
66
		$car = new Car('S500', 2016);
67
		$this->em->persist($car);
68
		$this->em->flush();
69
		
70
		$service = $this->getSearchService();
71
		$document = $service->createEmptyDocumentFromEntity($car);
72
		$this->assertAttributeCount(0, 'index', $service);
73
		$service->saveDocument($document);
74
		
75
		$this->assertAttributeCount(1, 'index', $service);
76
		
77
		$service->clearIndex();
78
		$this->assertAttributeCount(0, 'index', $service);
79
	}
80
81
	public function testRemoveDocument() {
82
		$service = $this->getSearchService();
83
		$result = $this->indexBeer($service);
84
		
85
		$service->removeDocument($result[1]);
86
		$this->assertAttributeCount(0, 'index', $service);
87
	}
88
89
	public function testAutocompletion() {
90
		$service = $this->getSearchService();
91
		$result = $this->indexBeer($service);
92
		
93
		$suggests = $service->autocomplete('He');
94
		$this->count(1, $suggests);
0 ignored issues
show
Unused Code introduced by
The call to DummySearchServiceTest::count() has too many arguments starting with 1.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
Unused Code introduced by
The call to the method StingerSoft\EntitySearch...rchServiceTest::count() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
95
		$this->assertContains($result[0]->getTitle(), $suggests);
96
	}
97
98
	public function testSearch() {
99
		$service = $this->getSearchService();
100
		$this->indexBeer($service);
101
		$service->search($this->getMockBuilder(Query::class)->getMockForAbstractClass());
102
	}
103
104
	/**
105
	 *
106
	 * {@inheritDoc}
107
	 *
108
	 * @see \StingerSoft\EntitySearchBundle\Tests\AbstractTestCase::getUsedEntityFixtures()
109
	 */
110
	protected function getUsedEntityFixtures() {
111
		return array(
112
			Beer::class,
113
			Car::class 
114
		);
115
	}
116
}