Skip to content

Commit c2a626e

Browse files
committed
#16 fix tests to get rid of Mockery
1 parent cff3a8b commit c2a626e

File tree

2 files changed

+18
-25
lines changed

2 files changed

+18
-25
lines changed

tests/Plugin/GetUrlTest.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,30 @@
22

33
namespace Enl\Flysystem\Cloudinary\Test\Plugin;
44

5-
use Enl\Flysystem\Cloudinary\ApiFacade;
65
use Enl\Flysystem\Cloudinary\CloudinaryAdapter;
76
use Enl\Flysystem\Cloudinary\Plugin\GetUrl;
87
use League\Flysystem\Filesystem;
98
use PHPUnit\Framework\TestCase;
10-
use Mockery as m;
119

1210
class GetUrlTest extends TestCase
1311
{
1412
public function testPassesTransformationToUrl()
1513
{
1614
list ($filesystem, $facade) = $this->mockFacade();
1715
$transformations = ['width' => 600, 'height' => 600];
18-
$facade->shouldReceive('url')
19-
->once()
20-
->with('test', $transformations)
21-
->andReturn('http://cloudinary.url/test');
16+
$facade->url('test.jpg', $transformations)->willReturn('http://cloudinary.url/test');
2217

2318
$content = $filesystem->getUrl('test.jpg', $transformations);
2419
$this->assertEquals('http://cloudinary.url/test', $content);
2520
}
2621

2722
private function mockFacade()
2823
{
29-
$facade = m::mock(ApiFacade::class);
30-
$filesystem = new Filesystem(new CloudinaryAdapter($facade), ['disable_asserts' => true]);
31-
$filesystem->addPlugin(new GetUrl($facade));
24+
$api = $this->prophesize('\Enl\Flysystem\Cloudinary\ApiFacade');
3225

33-
return [$filesystem, $facade];
26+
$filesystem = new Filesystem(new CloudinaryAdapter($api->reveal()), ['disable_asserts' => true]);
27+
$filesystem->addPlugin(new GetUrl($api->reveal()));
28+
29+
return [$filesystem, $api];
3430
}
3531
}

tests/Plugin/ReadTransformationTest.php

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,19 @@
22

33
namespace Enl\Flysystem\Cloudinary\Test\Plugin;
44

5-
use Enl\Flysystem\Cloudinary\ApiFacade;
65
use Enl\Flysystem\Cloudinary\CloudinaryAdapter;
76
use Enl\Flysystem\Cloudinary\Plugin\ReadTransformation;
87
use League\Flysystem\Filesystem;
98
use PHPUnit\Framework\TestCase;
10-
use Mockery as m;
119

1210
class ReadTransformationTest extends TestCase
1311
{
1412
public function testCallsReadIfNoTransformations()
1513
{
1614
list ($filesystem, $facade) = $this->mockFacade();
17-
$facade->shouldReceive('content')
18-
->once()
19-
->with('test')
20-
->andReturn(fopen('data://text/plain,test content','r'));
15+
$stream = 'data://text/plain,test content';
16+
$facade->content('test.jpg')
17+
->willReturn(fopen($stream, 'r'));
2118

2219
$content = $filesystem->readTransformation('test.jpg');
2320
$this->assertEquals('test content', $content);
@@ -27,21 +24,21 @@ public function testPassesTransformationToConvert()
2724
{
2825
list ($filesystem, $facade) = $this->mockFacade();
2926
$transformations = ['width' => 600, 'height' => 600];
30-
$facade->shouldReceive('content')
31-
->once()
32-
->with('test', $transformations)
33-
->andReturn(fopen('data://text/plain,transformed content','r'));
27+
$stream = 'data://text/plain,transformed content';
28+
$facade->content('test.jpg', $transformations)
29+
->willReturn(fopen($stream, 'r'));
3430

3531
$content = $filesystem->readTransformation('test.jpg', $transformations);
36-
$this->assertEquals('transformed content', $content);
32+
$this->assertEquals('transformed content', stream_get_contents($content));
3733
}
3834

3935
private function mockFacade()
4036
{
41-
$facade = m::mock(ApiFacade::class);
42-
$filesystem = new Filesystem(new CloudinaryAdapter($facade), ['disable_asserts' => true]);
43-
$filesystem->addPlugin(new ReadTransformation($facade));
37+
$api = $this->prophesize('\Enl\Flysystem\Cloudinary\ApiFacade');
4438

45-
return [$filesystem, $facade];
39+
$filesystem = new Filesystem(new CloudinaryAdapter($api->reveal()), ['disable_asserts' => true]);
40+
$filesystem->addPlugin(new ReadTransformation($api->reveal()));
41+
42+
return [$filesystem, $api];
4643
}
4744
}

0 commit comments

Comments
 (0)