ScriptHandlerTest::testInvalidConfiguration()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Incenteev\ParameterHandler\Tests;
4
5
use Incenteev\ParameterHandler\ScriptHandler;
6
7
class ScriptHandlerTest extends \PHPUnit_Framework_TestCase
8
{
9
    private $event;
10
    private $io;
11
    private $package;
12
13
    protected function setUp()
14
    {
15
        parent::setUp();
16
17
        $this->event = $this->prophesize('Composer\Script\Event');
18
        $this->io = $this->prophesize('Composer\IO\IOInterface');
19
        $this->package = $this->prophesize('Composer\Package\PackageInterface');
20
        $composer = $this->prophesize('Composer\Composer');
21
22
        $composer->getPackage()->willReturn($this->package);
23
        $this->event->getComposer()->willReturn($composer);
24
        $this->event->getIO()->willReturn($this->io);
25
    }
26
27
    /**
28
     * @dataProvider provideInvalidConfiguration
29
     */
30
    public function testInvalidConfiguration(array $extras, $exceptionMessage)
31
    {
32
        $this->package->getExtra()->willReturn($extras);
33
34
        chdir(__DIR__);
35
36
        $this->setExpectedException('InvalidArgumentException', $exceptionMessage);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
37
38
        ScriptHandler::buildParameters($this->event->reveal());
39
    }
40
41
    public function provideInvalidConfiguration()
42
    {
43
        return array(
44
            'no extra' => array(
45
                array(),
46
                'The parameter handler needs to be configured through the extra.incenteev-parameters setting.',
47
            ),
48
            'invalid type' => array(
49
                array('incenteev-parameters' => 'not an array'),
50
                'The extra.incenteev-parameters setting must be an array or a configuration object.',
51
            ),
52
            'invalid type for multiple file' => array(
53
                array('incenteev-parameters' => array('not an array')),
54
                'The extra.incenteev-parameters setting must be an array of configuration objects.',
55
            ),
56
            'no file' => array(
57
                array('incenteev-parameters' => array()),
58
                'The extra.incenteev-parameters.file setting is required to use this script handler.',
59
            ),
60
        );
61
    }
62
}
63