14 protected $cleanup = array();
16 public function setUp()
18 $this->loader = $this->getMockBuilder(
'Guzzle\Service\AbstractConfigLoader')
19 ->setMethods(array(
'build'))
20 ->getMockForAbstractClass();
23 public function tearDown()
25 foreach ($this->cleanup as $file) {
33 public function testOnlyLoadsSupportedTypes()
35 $this->loader->load(
new \stdClass());
42 public function testFileMustBeReadable()
44 $this->loader->load(
'fooooooo.json');
51 public function testMustBeSupportedExtension()
53 $this->loader->load(dirname(__DIR__) .
'/TestData/FileBody.txt');
60 public function testJsonMustBeValue()
62 $filename = tempnam(sys_get_temp_dir(),
'json') .
'.json';
63 file_put_contents($filename,
'{/{./{}foo');
64 $this->cleanup[] = $filename;
65 $this->loader->load($filename);
72 public function testPhpFilesMustReturnAnArray()
74 $filename = tempnam(sys_get_temp_dir(),
'php') .
'.php';
75 file_put_contents($filename,
'<?php $fdr = false;');
76 $this->cleanup[] = $filename;
77 $this->loader->load($filename);
80 public function testLoadsPhpFileIncludes()
82 $filename = tempnam(sys_get_temp_dir(),
'php') .
'.php';
83 file_put_contents($filename,
'<?php return array("foo" => "bar");');
84 $this->cleanup[] = $filename;
85 $this->loader->expects($this->exactly(1))->method(
'build')->will($this->returnArgument(0));
86 $config = $this->loader->load($filename);
87 $this->assertEquals(array(
'foo' =>
'bar'), $config);
90 public function testCanCreateFromJson()
92 $file = dirname(__DIR__) .
'/TestData/services/json1.json';
94 $this->loader->expects($this->exactly(1))->method(
'build')->will($this->returnArgument(0));
95 $data = $this->loader->load($file);
97 $this->assertArrayHasKey(
'includes', $data);
98 $this->assertArrayHasKey(
'services', $data);
99 $this->assertInternalType(
'array', $data[
'services'][
'foo']);
100 $this->assertInternalType(
'array', $data[
'services'][
'abstract']);
101 $this->assertInternalType(
'array', $data[
'services'][
'mock']);
102 $this->assertEquals(
'bar', $data[
'services'][
'foo'][
'params'][
'baz']);
105 public function testUsesAliases()
107 $file = dirname(__DIR__) .
'/TestData/services/json1.json';
108 $this->loader->addAlias(
'foo', $file);
110 $this->loader->expects($this->exactly(1))->method(
'build')->will($this->returnArgument(0));
111 $data = $this->loader->load(
'foo');
112 $this->assertEquals(
'bar', $data[
'services'][
'foo'][
'params'][
'baz']);
119 public function testCanRemoveAliases()
121 $file = dirname(__DIR__) .
'/TestData/services/json1.json';
122 $this->loader->addAlias(
'foo.json', $file);
123 $this->loader->removeAlias(
'foo.json');
124 $this->loader->load(
'foo.json');
127 public function testCanLoadArraysWithIncludes()
129 $file = dirname(__DIR__) .
'/TestData/services/json1.json';
130 $config = array(
'includes' => array($file));
132 $this->loader->expects($this->exactly(1))->method(
'build')->will($this->returnArgument(0));
133 $data = $this->loader->load($config);
134 $this->assertEquals(
'bar', $data[
'services'][
'foo'][
'params'][
'baz']);
137 public function testDoesNotEnterInfiniteLoop()
139 $prefix = $file = dirname(__DIR__) .
'/TestData/description';
140 $this->loader->load(
"{$prefix}/baz.json");
141 $this->assertCount(4, $this->readAttribute($this->loader,
'loadedFiles'));
143 $this->loader->load(
"{$prefix}/../test_service2.json");
144 $this->assertCount(1, $this->readAttribute($this->loader,
'loadedFiles'));
146 $this->loader->load(
"{$prefix}/baz.json");
147 $this->assertCount(4, $this->readAttribute($this->loader,
'loadedFiles'));