slickframework /
configuration
| 1 | <?php |
||||||
| 2 | |||||||
| 3 | /** |
||||||
| 4 | * This file is part of Configuration |
||||||
| 5 | * |
||||||
| 6 | * For the full copyright and license information, please view the LICENSE |
||||||
| 7 | * file that was distributed with this source code. |
||||||
| 8 | */ |
||||||
| 9 | |||||||
| 10 | namespace spec\Slick\Configuration\Driver; |
||||||
| 11 | |||||||
| 12 | use Slick\Configuration\ConfigurationInterface; |
||||||
| 13 | use Slick\Configuration\Driver\Php; |
||||||
| 14 | use PhpSpec\ObjectBehavior; |
||||||
| 15 | use Slick\Configuration\Exception\FileNotFoundException; |
||||||
| 16 | use Slick\Configuration\Exception\ParserErrorException; |
||||||
| 17 | |||||||
| 18 | /** |
||||||
| 19 | * Php Specs |
||||||
| 20 | * |
||||||
| 21 | * @package spec\Slick\Configuration\Driver |
||||||
| 22 | */ |
||||||
| 23 | class PhpSpec extends ObjectBehavior |
||||||
| 24 | { |
||||||
| 25 | private $file; |
||||||
| 26 | |||||||
| 27 | private $dummyFile; |
||||||
| 28 | |||||||
| 29 | function let() |
||||||
| 30 | { |
||||||
| 31 | $this->file = __DIR__ . '/fixtures/settings.php'; |
||||||
| 32 | $this->dummyFile = __DIR__ . '/fixtures/dummy.txt'; |
||||||
| 33 | $this->beConstructedWith($this->file); |
||||||
| 34 | } |
||||||
| 35 | |||||||
| 36 | function its_a_configuration_driver_for_php_arrays() |
||||||
|
0 ignored issues
–
show
|
|||||||
| 37 | { |
||||||
| 38 | $this->shouldBeAnInstanceOf(ConfigurationInterface::class); |
||||||
| 39 | } |
||||||
| 40 | |||||||
| 41 | function it_is_initializable_with_a_path_to_a_settings_file() |
||||||
| 42 | { |
||||||
| 43 | $this->shouldHaveType(Php::class); |
||||||
| 44 | } |
||||||
| 45 | |||||||
| 46 | function it_throws_an_exception_if_settings_file_cannot_be_found() |
||||||
| 47 | { |
||||||
| 48 | $this->beConstructedWith('/_some/missing/file/path.php'); |
||||||
| 49 | $this->shouldThrow(FileNotFoundException::class) |
||||||
| 50 | ->duringInstantiation(); |
||||||
| 51 | } |
||||||
| 52 | |||||||
| 53 | function it_throws_an_exception_if_file_cannot_be_parsed() |
||||||
| 54 | { |
||||||
| 55 | $this->beConstructedWith($this->dummyFile); |
||||||
| 56 | $this->shouldThrow(ParserErrorException::class) |
||||||
| 57 | ->duringInstantiation(); |
||||||
| 58 | } |
||||||
| 59 | |||||||
| 60 | function it_retrieves_a_configuration_value_stored_under_a_key() |
||||||
| 61 | { |
||||||
| 62 | $this->get('foo')->shouldBe('bar'); |
||||||
|
0 ignored issues
–
show
The method
get() does not exist on spec\Slick\Configuration\Driver\PhpSpec. Since you implemented __call, consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 63 | } |
||||||
| 64 | |||||||
| 65 | function it_returns_a_default_value_if_a_given_key_is_not_found() |
||||||
| 66 | { |
||||||
| 67 | $setting = $this->get('baz', true); |
||||||
| 68 | $setting->shouldBeBoolean(); |
||||||
| 69 | $setting->shouldBe(true); |
||||||
| 70 | } |
||||||
| 71 | |||||||
| 72 | function it_retrieves_a_value_recursively_using_a_dot_notation() |
||||||
| 73 | { |
||||||
| 74 | $this->get('first.second.third')->shouldBe(123); |
||||||
| 75 | } |
||||||
| 76 | |||||||
| 77 | function it_sets_a_value_under_a_given_key() |
||||||
| 78 | { |
||||||
| 79 | $this->set('other', 'value')->shouldBe($this->getWrappedObject()); |
||||||
|
0 ignored issues
–
show
The method
set() does not exist on spec\Slick\Configuration\Driver\PhpSpec. Since you implemented __call, consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 80 | $this->get('other')->shouldBe('value'); |
||||||
| 81 | } |
||||||
| 82 | |||||||
| 83 | function it_sets_a_value_recursively_using_a_dot_notation() |
||||||
| 84 | { |
||||||
| 85 | $this->set('value.under.deep', 'path')->shouldBe($this->getWrappedObject()); |
||||||
| 86 | $this->get('value.under.deep')->shouldBe('path'); |
||||||
| 87 | } |
||||||
| 88 | } |
||||||
| 89 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.