Completed
Push — develop ( 8fda15...dbbcf5 )
by Jaap
14s
created

phpDocumentor/Translator/ServiceProviderTest.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
* phpDocumentor
4
*
5
* PHP Version 5.3
6
*
7
* @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
8
* @license http://www.opensource.org/licenses/mit-license.php MIT
9
* @link http://phpdoc.org
10
*/
11
12
namespace phpDocumentor\Translator;
13
14
use Cilex\Application;
15
use Mockery as m;
16
17
/**
18
 * Tests for phpDocumentor\Translator\ServiceProvider
19
 */
20
class ServiceProviderTest extends \Mockery\Adapter\Phpunit\MockeryTestCase
21
{
22
    /**
23
     * Dummy locale.
24
     *
25
     * @var string
26
     */
27
    protected $locale = 'foobar';
28
29
    /** @var ServiceProvider $fixture */
30
    protected $fixture = null;
31
32
    /** @var Application $application */
33
    protected $application = null;
34
35
    /**
36
     * Setup test fixture and mocks used in this TestCase
37
     */
38
    protected function setUp()
39
    {
40
        $this->application = new Application('test');
41
        $this->application['config'] = m::mock('phpDocumentor\Configuration');
42
43
        $this->application['config']->shouldReceive('getTranslator->getLocale')
44
            ->andReturn($this->locale);
45
        $this->fixture = new ServiceProvider();
46
    }
47
48
    /**
49
     * @covers phpDocumentor\Translator\ServiceProvider::register
50
     */
51
    public function testRegisterSetsTranslator()
52
    {
53
        $this->fixture->register($this->application);
0 ignored issues
show
The call to the method phpDocumentor\Translator...iceProvider::register() 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...
54
        $translator = $this->application['translator'];
55
56
        $this->assertSame($this->locale, $this->application['translator.locale']);
57
        $this->assertInstanceOf('phpDocumentor\Translator\Translator', $translator);
58
        $this->assertSame($this->application['translator.locale'], $translator->getLocale());
59
    }
60
}
61