Skip to content

Commit

Permalink
Got test coverage back to 100% + fixed incompatible array declaration…
Browse files Browse the repository at this point in the history
… (php 5.3 vs. Php 5.4)
  • Loading branch information
Raphael Antonmattei committed Feb 18, 2016
1 parent af10027 commit 5c83017
Showing 1 changed file with 52 additions and 10 deletions.
62 changes: 52 additions & 10 deletions tests/Config/Loader/ClassLoader/HandlerLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public function testHandlerLoader()
$loader = new HandlerLoader($options, $formatters, $processors);

$this->assertNotEquals($original, $options);
$this->assertEquals(new LineFormatter(), $options['formatter']);
$this->assertContains($dummyClosure, $options['processors']);
$this->assertContains($dummyClosure, $options['processors']);
$this->assertSame($formatters['test_formatter'], $options['formatter']);
$this->assertSame($processors['test_processor_1'], $options['processors'][0]);
$this->assertSame($processors['test_processor_2'], $options['processors'][1]);
}

public function testHandlerLoaderWithNoOptions()
Expand Down Expand Up @@ -83,6 +83,45 @@ public function testHandlerLoaderWithInvalidProcessor()
$loader = new HandlerLoader($options, $formatters, $processors);
}

/**
* @expectedException InvalidArgumentException
*/
public function testHandlerLoaderWithInvalidHandler()
{
$dummyClosure = function () {
// Empty function
};
$options = array(
'handler' => 'test_handler'
);

$formatters = array();
$processors = array();
$handlers = array('test_handlerXYZ' => $dummyClosure);
$loader = new HandlerLoader($options, $formatters, $processors, $handlers);
}

/**
* @expectedException InvalidArgumentException
*/
public function testHandlerLoaderWithInvalidHandlers()
{
$dummyClosure = function () {
// Empty function
};
$options = array(
'handlers' => array('test_handler_1', 'test_handler_2')
);

$formatters = array();
$processors = array();
$handlers = array(
'test_handler_1' => $dummyClosure,
'test_handlerXYZ' => $dummyClosure
);
$loader = new HandlerLoader($options, $formatters, $processors, $handlers);
}

/**
* Check if the handler exists for a given class and option
* Also checks that it a callable and return it
Expand Down Expand Up @@ -221,14 +260,17 @@ public function testHandlerForProcessor()

public function testReplacesHandlerNamesInOptionsArrayWithLoadedCallable()
{
$options = [
'handlers' => [
$options = array(
'handlers' => array(
'foo',
'bar',
],
),
'handler' => 'baz'
];
$handlers = [
);

$formatters = array();
$processors = array();
$handlers = array(
'foo' => function () {
return 'foo';
},
Expand All @@ -238,9 +280,9 @@ public function testReplacesHandlerNamesInOptionsArrayWithLoadedCallable()
'baz' => function () {
return 'baz';
},
];
);

$loader = new HandlerLoader($options, [], [], $handlers);
$loader = new HandlerLoader($options, $formatters, $processors, $handlers);

$this->assertSame($handlers['foo'], $options['handlers'][0]);
$this->assertSame($handlers['bar'], $options['handlers'][1]);
Expand Down

0 comments on commit 5c83017

Please sign in to comment.