arinasystems /
laravel-json-response
| 1 | <?php |
||
| 2 | |||
| 3 | namespace ArinaSystems\JsonResponse\Tests; |
||
| 4 | |||
| 5 | use ArinaSystems\JsonResponse\Option; |
||
| 6 | use Illuminate\Support\Facades\Config; |
||
| 7 | |||
| 8 | class OptionTest extends TestCase |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * @var \ArinaSystems\JsonResponse\Option |
||
| 12 | */ |
||
| 13 | protected $options; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @var array |
||
| 17 | */ |
||
| 18 | protected $config; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Setup the test environment. |
||
| 22 | * |
||
| 23 | * @return void |
||
| 24 | */ |
||
| 25 | public function setUp(): void |
||
| 26 | { |
||
| 27 | parent::setUp(); |
||
| 28 | |||
| 29 | $this->config = Config::get('json-response'); |
||
| 30 | $this->options = new Option($this->config); |
||
| 31 | } |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @test |
||
| 35 | */ |
||
| 36 | public function it_loads_the_given_config_array() |
||
| 37 | { |
||
| 38 | $this->assertEquals($this->options->all(), $this->config); |
||
| 39 | } |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @test |
||
| 43 | */ |
||
| 44 | public function it_returns_a_value_of_given_key() |
||
| 45 | { |
||
| 46 | $this->assertEquals($this->options->get('attributes'), $this->config['attributes']); |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @test |
||
| 51 | */ |
||
| 52 | public function it_returns_a_value_of_given_key_with_default_value() |
||
| 53 | { |
||
| 54 | $this->assertEquals($this->options->get('some_key', 'default'), 'default'); |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @test |
||
| 59 | */ |
||
| 60 | public function it_can_set_a_value_of_given_key() |
||
| 61 | { |
||
| 62 | $value = $this->options->set('some_key', 'some_value')->get('some_key'); |
||
| 63 | $this->assertEquals($value, 'some_value'); |
||
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @test |
||
| 68 | */ |
||
| 69 | public function it_can_set_an_array_of_keys_and_values() |
||
| 70 | { |
||
| 71 | $value = $this->options->set([ |
||
| 72 | 'some_key' => 'some_value', |
||
| 73 | 'another_some_key' => 'another_some_value', |
||
| 74 | ]); |
||
| 75 | |||
| 76 | $this->assertEquals($value->get('some_key'), 'some_value'); |
||
| 77 | $this->assertEquals($value->get('another_some_key'), 'another_some_value'); |
||
| 78 | } |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @test |
||
| 82 | */ |
||
| 83 | public function it_can_set_a_value_of_given_key_with_magic_methods() |
||
| 84 | { |
||
| 85 | $this->options->some_key = 'some_value'; |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 86 | $value = $this->options->get('some_key'); |
||
| 87 | |||
| 88 | $this->assertEquals($value, 'some_value'); |
||
| 89 | } |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @test |
||
| 93 | */ |
||
| 94 | public function it_can_get_value_of_given_key_with_magic_methods() |
||
| 95 | { |
||
| 96 | $this->assertEquals($this->options->attributes, $this->config['attributes']); |
||
| 97 | } |
||
| 98 | } |
||
| 99 |