1
|
|
|
<?php namespace Nwidart\Modules\Tests; |
2
|
|
|
|
3
|
|
|
use Nwidart\Modules\Json; |
4
|
|
|
|
5
|
|
|
class JsonTest extends BaseTestCase |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* @var Json |
9
|
|
|
*/ |
10
|
|
|
private $json; |
11
|
|
|
|
12
|
|
|
public function setUp() |
13
|
|
|
{ |
14
|
|
|
parent::setUp(); |
15
|
|
|
$path = __DIR__ . '/stubs/module.json'; |
16
|
|
|
$this->json = new Json($path, $this->app['files']); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
/** @test */ |
20
|
|
|
public function it_gets_the_file_path() |
21
|
|
|
{ |
22
|
|
|
$path = __DIR__ . '/stubs/module.json'; |
23
|
|
|
|
24
|
|
|
$this->assertEquals($path, $this->json->getPath()); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** @test */ |
28
|
|
|
public function it_gets_attributes_from_json_file() |
29
|
|
|
{ |
30
|
|
|
$this->assertEquals('Order', $this->json->get('name')); |
31
|
|
|
$this->assertEquals('order', $this->json->get('alias')); |
32
|
|
|
$this->assertEquals('My demo module', $this->json->get('description')); |
33
|
|
|
$this->assertEquals('0.1', $this->json->get('version')); |
34
|
|
|
$this->assertEquals(['my', 'stub', 'module'], $this->json->get('keywords')); |
35
|
|
|
$this->assertEquals(1, $this->json->get('active')); |
36
|
|
|
$this->assertEquals(1, $this->json->get('order')); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** @test */ |
40
|
|
|
public function it_reads_attributes_from_magic_get_method() |
41
|
|
|
{ |
42
|
|
|
$this->assertEquals('Order', $this->json->name); |
|
|
|
|
43
|
|
|
$this->assertEquals('order', $this->json->alias); |
|
|
|
|
44
|
|
|
$this->assertEquals('My demo module', $this->json->description); |
|
|
|
|
45
|
|
|
$this->assertEquals('0.1', $this->json->version); |
|
|
|
|
46
|
|
|
$this->assertEquals(['my', 'stub', 'module'], $this->json->keywords); |
|
|
|
|
47
|
|
|
$this->assertEquals(1, $this->json->active); |
|
|
|
|
48
|
|
|
$this->assertEquals(1, $this->json->order); |
|
|
|
|
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** @test */ |
52
|
|
|
public function it_makes_json_class() |
53
|
|
|
{ |
54
|
|
|
$path = __DIR__ . '/stubs/module.json'; |
55
|
|
|
$json = Json::make($path, $this->app['files']); |
56
|
|
|
|
57
|
|
|
$this->assertInstanceOf(Json::class, $json); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.