extension /tests/FinderTest.php

Language PHP Lines 278
MD5 Hash 8c8ae8f2a5c72a375a7e15ac53ead88f Estimated Cost $4,855 (why?)
Repository https://github.com/orchestral/extension.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<?php namespace Orchestra\Extension\TestCase;

use Mockery as m;
use Illuminate\Container\Container;
use Illuminate\Support\Collection;
use Orchestra\Extension\Finder;

class FinderTest extends \PHPUnit_Framework_TestCase
{
    /**
     * Teardown the test environment.
     */
    public function tearDown()
    {
        m::close();
    }

    /**
     * Test constructing a new Orchestra\Extension\Finder.
     *
     * @test
     */
    public function testConstructMethod()
    {
        $config['path.app'] = '/foo/app';
        $config['path.base'] = '/foo/path';

        $stub = new Finder(m::mock('\Illuminate\Filesystem\Filesystem'), $config);

        $refl  = new \ReflectionObject($stub);
        $paths = $refl->getProperty('paths');
        $paths->setAccessible(true);

        $this->assertEquals(
            array('/foo/app/', '/foo/path/vendor/*/*/', '/foo/path/workbench/*/*/'),
            $paths->getValue($stub)
        );

        $stub->addPath('/foo/public');

        $this->assertEquals(
            array('/foo/app/', '/foo/path/vendor/*/*/', '/foo/path/workbench/*/*/', '/foo/public'),
            $paths->getValue($stub)
        );
    }

    /**
     * Test Orchestra\Extension\Finder::detect() method.
     *
     * @test
     */
    public function testDetectMethod()
    {
        $config['path.app'] = '/foo/app';
        $config['path.base'] = '/foo/path';

        $files = m::mock('\Illuminate\Filesystem\Filesystem');

        $files->shouldReceive('glob')->once()
                ->with('/foo/app/orchestra.json')->andReturn(array('/foo/app/orchestra.json'))
            ->shouldReceive('get')->once()
                ->with('/foo/app/orchestra.json')->andReturn('{"name":"Application"}')
            ->shouldReceive('glob')->once()
                ->with('/foo/path/vendor/*/*/orchestra.json')
                ->andReturn(array('/foo/path/vendor/laravel/framework/orchestra.json', '/foo/orchestra.js'))
            ->shouldReceive('get')->once()
                ->with('/foo/path/vendor/laravel/framework/orchestra.json')
                ->andReturn('{"name":"Laravel Framework","path": "vendor::laravel/framework"}')
            ->shouldReceive('glob')->once()
                ->with('/foo/path/workbench/*/*/orchestra.json')->andReturn(array());

        $stub = new Finder($files, $config);

        $expected = new Collection(array(
            'laravel/framework' => array(
                'path'        => 'vendor::laravel/framework',
                'source-path' => 'vendor::laravel/framework',
                'name'        => 'Laravel Framework',
                'description' => null,
                'author'      => null,
                'url'         => null,
                'version'     => '>0',
                'config'      => array(),
                'autoload'    => array(),
                'provide'     => array(),
            ),
            'app' => array(
                'path'        => 'app::',
                'source-path' => 'app::',
                'name'        => 'Application',
                'description' => null,
                'author'      => null,
                'url'         => null,
                'version'     => '>0',
                'config'      => array(),
                'autoload'    => array(),
                'provide'     => array(),
            ),
        ));

        $this->assertEquals($expected, $stub->detect());
    }

    /**
     * Test Orchestra\Extension\Finder::detect() method giveb reserved name
     * throws exception.
     *
     * @expectedException \RuntimeException
     */
    public function testDetectMethodGivenReservedNameThrowsException()
    {
        $config['path.app'] = '/foo/app';
        $config['path.base'] = '/foo/path';

        $files = m::mock('\Illuminate\Filesystem\Filesystem');

        $files->shouldReceive('glob')->once()
                ->with('/foo/app/orchestra.json')->andReturn(array('/foo/app/orchestra.json'))
            ->shouldReceive('get')->once()
                ->with('/foo/app/orchestra.json')->andReturn('{"name":"Application"}')
            ->shouldReceive('glob')->once()
                ->with('/foo/path/vendor/*/*/orchestra.json')
                ->andReturn(array('/foo/path/vendor/orchestra/foundation/orchestra.json'));

        $stub = new Finder($files, $config);
        $stub->detect();
    }

    /**
     * Test Orchestra\Extension\Finder::detect() method throws
     * exception when unable to parse json manifest file.
     *
     * @expectedException \Orchestra\Extension\ManifestRuntimeException
     */
    public function testDetectMethodThrowsException()
    {
        $config['path.app'] = '/foo/app';
        $config['path.base'] = '/foo/path';

        $files = m::mock('\Illuminate\Filesystem\Filesystem');

        $files->shouldReceive('glob')
                ->with('/foo/app/orchestra.json')->once()
                ->andReturn(array())
            ->shouldReceive('glob')
                ->with('/foo/path/vendor/*/*/orchestra.json')->once()
                ->andReturn(array('/foo/path/vendor/laravel/framework/orchestra.json'))
            ->shouldReceive('glob')
                ->with('/foo/path/workbench/*/*/orchestra.json')->never()
                ->andReturn(array())
            ->shouldReceive('get')
                ->with('/foo/path/vendor/laravel/framework/orchestra.json')->once()
                ->andReturn('{"name":"Laravel Framework}');

        with(new Finder($files, $config))->detect();
    }

    /**
     * Test Orchestra\Extension\Finder::guessExtensionPath() method.
     *
     * @test
     * @dataProvider extensionPathProvider
     */
    public function testGuessExtensionPathMethod($output, $expected)
    {
        $config['path.app'] = '/foo/path/app';
        $config['path.base'] = '/foo/path';

        $stub = new Finder(m::mock('\Illuminate\Filesystem\Filesystem'), $config);
        $this->assertEquals($expected, $stub->guessExtensionPath($output));
    }

    /**
     * Test Orchestra\Extension\Finder::resolveExtensionNamespace() method
     * with mixed directory separator.
     *
     * @test
     * @dataProvider extensionManifestProvider
     */
    public function testResolveExtensionNamespace($path, $expected, $output)
    {
        $config['path.app'] = '/foo/path/app';
        $config['path.base'] = '/foo/path';

        $stub = new Finder(m::mock('\Illuminate\Filesystem\Filesystem'), $config);
        $this->assertEquals($expected, $stub->resolveExtensionNamespace($output));
    }

    /**
     * Test Orchestra\Extension\Finder::resolveExtensionPath() method.
     *
     * @test
     * @dataProvider extensionPathProvider
     */
    public function testResolveExtensionPathMethod($expected, $output)
    {
        $config['path.app'] = '/foo/path/app';
        $config['path.base'] = '/foo/path';

        $stub = new Finder(m::mock('\Illuminate\Filesystem\Filesystem'), $config);
        $this->assertEquals($expected, $stub->resolveExtensionPath($output));
    }

    /**
     * Extension Path provider.
     */
    public function extensionManifestProvider()
    {
        $windowsPath['path.app'] = 'c:\www\laravel\app';
        $windowsPath['path.base'] = 'c:\www\laravel';

        $unixPath['path.app'] = '/var/www/laravel/app';
        $unixPath['path.base'] = '/var/www/laravel';

        return array(
            array(
                $windowsPath,
                array("laravel", "app"),
                "c:\www\laravel\app/orchestra.json",
            ),
            array(
                $windowsPath,
                array("orchestra", "control"),
                "c:\www\laravel\vendor/orchestra/control/orchestra.json",
            ),
            array(
                $windowsPath,
                array("orchestra", "story"),
                "c:\www\laravel\vendor/orchestra/story/orchestra.json",
            ),
            array(
                $windowsPath,
                array("laravel", "app"),
                "c:\www\laravel\app\orchestra.json",
            ),
            array(
                $windowsPath,
                array("orchestra", "control"),
                "c:\www\laravel\vendor\orchestra\control\orchestra.json",
            ),
            array(
                $windowsPath,
                array("orchestra", "story"),
                "c:\www\laravel\vendor\orchestra\story\orchestra.json",
            ),
            array(
                $unixPath,
                array("laravel", "app"),
                "/var/www/laravel/app/orchestra.json",
            ),
            array(
                $unixPath,
                array("orchestra", "control"),
                "/var/www/laravel/vendor/orchestra/control/orchestra.json",
            ),
            array(
                $unixPath,
                array("orchestra", "story"),
                "/var/www/laravel/vendor/orchestra/story/orchestra.json",
            ),
        );
    }

    /**
     * Extension Path provider.
     */
    public function extensionPathProvider()
    {
        return array(
            array("foobar", "foobar"),
            array("/foo/path/app/foobar", "app::foobar"),
            array("/foo/path/vendor/foobar", "vendor::foobar"),
            array("/foo/path/workbench/foobar", "workbench::foobar"),
            array("/foo/path/foobar", "base::foobar"),
        );
    }
}
Back to Top