diff --git a/composer.json b/composer.json index 1daee32..12ddece 100644 --- a/composer.json +++ b/composer.json @@ -21,8 +21,7 @@ }, "autoload": { "classmap": [ - "src/migrations", - "tests/TestCase.php" + "src/migrations" ], "psr-0": { "Codesleeve\\Stapler": "src/" diff --git a/phpunit.xml b/phpunit.xml index 12bee7a..fd46f25 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,7 +1,7 @@ - - ./tests/ + + ./tests/Codesleeve/Stapler/ \ No newline at end of file diff --git a/tests/Stapler/AttachmentTest.php b/tests/Codesleeve/Stapler/AttachmentTest.php similarity index 97% rename from tests/Stapler/AttachmentTest.php rename to tests/Codesleeve/Stapler/AttachmentTest.php index 589d69e..29a3a9a 100644 --- a/tests/Stapler/AttachmentTest.php +++ b/tests/Codesleeve/Stapler/AttachmentTest.php @@ -1,13 +1,13 @@ -buildMockIOWrapper(); - + $config = m::mock('Codesleeve\Stapler\Config', ['mockAttachment', []]); - + $instance = m::mock(); $instance->shouldReceive('setAttribute')->once()->with('mockAttachment_file_name', ''); $instance->shouldReceive('setAttribute')->once()->with('mockAttachment_file_size', ''); @@ -52,7 +52,7 @@ public function testSetUploadedFile() /** * Test that the url method returns the url to a file that has been uploaded. - * + * * @return void */ public function testUrlReturnsAUrl() @@ -70,7 +70,7 @@ public function testUrlReturnsAUrl() /** * Test that the url method returns the default url when no file has been uploaded. - * + * * @return void */ public function testUrlReturnsTheDefaultUrl() @@ -80,13 +80,13 @@ public function testUrlReturnsTheDefaultUrl() $attachment = m::mock('Codesleeve\Stapler\Attachment')->makePartial(); $attachment->shouldReceive('originalFilename')->once()->andReturn(false); $attachment->setConfig($config); - + $this->assertEquals('', $attachment->url()); } /** * Test that the path method returns the path to a file that has been uploaded. - * + * * @return void */ public function testPathReturnsAPath() @@ -104,7 +104,7 @@ public function testPathReturnsAPath() /** * Test that the path method returns the default path when no file has been uploaded. - * + * * @return void */ public function testPathReturnsTheDefaultPath() @@ -114,19 +114,19 @@ public function testPathReturnsTheDefaultPath() $attachment = m::mock('Codesleeve\Stapler\Attachment')->makePartial(); $attachment->shouldReceive('originalFilename')->once()->andReturn(false); $attachment->setConfig($config); - + $this->assertEquals('/public', $attachment->path()); } /** * Test that the createdAt method is working correctly. - * + * * @return void */ public function testCreatedAt() { $config = m::mock('Codesleeve\Stapler\Config', ['mockAttachment', []]); - + $instance = m::mock(); $instance->shouldReceive('getAttribute')->once()->with('mockAttachment_created_at')->andReturn('foo'); @@ -139,13 +139,13 @@ public function testCreatedAt() /** * Test that the updatedAt method is working correctly. - * + * * @return void */ public function testUpdatedAt() { $config = m::mock('Codesleeve\Stapler\Config', ['mockAttachment', []]); - + $instance = m::mock(); $instance->shouldReceive('getAttribute')->once()->with('mockAttachment_updated_at')->andReturn('foo'); @@ -158,13 +158,13 @@ public function testUpdatedAt() /** * Test that the contentType method is working correctly. - * + * * @return void */ public function testContentType() { $config = m::mock('Codesleeve\Stapler\Config', ['mockAttachment', []]); - + $instance = m::mock(); $instance->shouldReceive('getAttribute')->once()->with('mockAttachment_content_type')->andReturn('foo'); @@ -177,13 +177,13 @@ public function testContentType() /** * Test that the size method is working correctly. - * + * * @return void */ public function testSize() { $config = m::mock('Codesleeve\Stapler\Config', ['mockAttachment', []]); - + $instance = m::mock(); $instance->shouldReceive('getAttribute')->once()->with('mockAttachment_file_size')->andReturn('foo'); @@ -196,13 +196,13 @@ public function testSize() /** * Test that the originalFilename method is working correctly. - * + * * @return void */ public function testOriginalFilename() { $config = m::mock('Codesleeve\Stapler\Config', ['mockAttachment', []]); - + $instance = m::mock(); $instance->shouldReceive('getAttribute')->once()->with('mockAttachment_file_name')->andReturn('foo'); @@ -215,7 +215,7 @@ public function testOriginalFilename() /** * Test that the afterSave method is working correctly. - * + * * @return void */ public function testAfterSave() @@ -232,7 +232,7 @@ public function testAfterSave() /** * Test that the beforeDelelete method is functioning properly. - * + * * @return void */ public function testBeforeDelete() @@ -249,7 +249,7 @@ public function testBeforeDelete() /** * Test the the afterDelete method is working correctly. - * + * * @return void */ /*public function testAfterDelete() @@ -271,8 +271,8 @@ public function testBeforeDelete() /** * Test that the destroy method is functioning correctly. - * - * @return void + * + * @return void */ public function testDestroy() { @@ -286,14 +286,14 @@ public function testDestroy() /** * Test that the clear method is working correctly when passed a * specific set of styles to clear. - * + * * @return void */ public function testClearWithStyles() { $attachment = m::mock('Codesleeve\Stapler\Attachment')->makePartial(); $attachment->shouldReceive('path')->once()->with('foo')->andReturn('bar'); - + $attachment->clear(['foo']); $this->assertEquals(['bar'], $attachment->getQueuedForDeletion()); @@ -302,14 +302,14 @@ public function testClearWithStyles() /** * Test that the clear method is working correctly when no styles are passed * and a file has already been uploaded and preserve files is set to false. - * + * * @return void */ public function testClearWithoutStylesAndWithUploadedFile() { $config = m::mock('Codesleeve\Stapler\Config', [ 'mockAttachment', [ - 'preserve_files' => false, + 'preserve_files' => false, 'styles' => ['foo' => ''], 'convert_options' => [] ] @@ -335,7 +335,7 @@ public function testClearWithoutStylesAndWithUploadedFile() /** * Test that the clear method is working correctly when no styles are passed * and a file has already been uploaded and preserve files is set to true. - * + * * @return void */ public function testClearWithoutStylesAndWithUploadedFileAndPreserveFiles() @@ -360,7 +360,7 @@ public function testClearWithoutStylesAndWithUploadedFileAndPreserveFiles() /** * Test that the getInstanceClass method is working correctly. - * + * * @return void */ public function testGetInstanceClass() @@ -375,7 +375,7 @@ public function testGetInstanceClass() /** * Build a mock IOWrapper object. - * + * * @return IOWrapper */ protected function buildMockIOWrapper() @@ -384,7 +384,7 @@ protected function buildMockIOWrapper() $mockUploadedFile->shouldReceive('getFilename')->once(); $mockUploadedFile->shouldReceive('getSize')->once(); $mockUploadedFile->shouldReceive('getMimeType')->once(); - + $IOWrapper = m::mock('Codesleeve\Stapler\IOWrapper'); $IOWrapper->shouldReceive('make')->once()->andReturn($mockUploadedFile); diff --git a/tests/Stapler/ConfigTest.php b/tests/Codesleeve/Stapler/ConfigTest.php similarity index 83% rename from tests/Stapler/ConfigTest.php rename to tests/Codesleeve/Stapler/ConfigTest.php index be7bcff..5391e8f 100644 --- a/tests/Stapler/ConfigTest.php +++ b/tests/Codesleeve/Stapler/ConfigTest.php @@ -1,13 +1,13 @@ - 'bar', + 'foo' => 'bar', 'styles' => ['baz' => ''], 'convert_options' => [] ] diff --git a/tests/Stapler/File/Image/ResizerTest.php b/tests/Codesleeve/Stapler/File/Image/ResizerTest.php similarity index 69% rename from tests/Stapler/File/Image/ResizerTest.php rename to tests/Codesleeve/Stapler/File/Image/ResizerTest.php index 9e8c7a2..e4b9f66 100644 --- a/tests/Stapler/File/Image/ResizerTest.php +++ b/tests/Codesleeve/Stapler/File/Image/ResizerTest.php @@ -1,17 +1,20 @@ -uploadedFile(); $originalSize = new Box(600, 400); @@ -21,7 +24,7 @@ public function testResizeCrop() $image = $this->mockImage($originalSize, $expectedResize, $expectedCropPoint, $expectedCropBox); $imageProcessor = $this->mockImageProcessor($image); - $resizer = new Codesleeve\Stapler\File\Image\Resizer($imageProcessor); + $resizer = new Resizer($imageProcessor); $style = $this->styleObject('thumbnail', '512x512#'); $file = $resizer->resize($uploadedFile, $style); @@ -29,10 +32,10 @@ public function testResizeCrop() /** * Test resize cropping edge case. - * - * @return void + * + * @return void */ - public function testResizeCropEdgecase() + public function testResizeCropEdgecase() { $uploadedFile = $this->uploadedFile(); $originalSize = new Box(1000, 653); @@ -42,7 +45,7 @@ public function testResizeCropEdgecase() $image = $this->mockImage($originalSize, $expectedResize, $expectedCropPoint, $expectedCropBox); $imageProcessor = $this->mockImageProcessor($image); - $resizer = new Codesleeve\Stapler\File\Image\Resizer($imageProcessor); + $resizer = new Resizer($imageProcessor); $style = $this->styleObject('thumbnail', '440x244#'); $file = $resizer->resize($uploadedFile, $style); @@ -50,28 +53,28 @@ public function testResizeCropEdgecase() /** * Helper method to build a mock Stapler UploadedFile object. - * - * @return UploadedFile + * + * @return UploadedFile */ - protected function uploadedFile() + protected function uploadedFile() { - $path = __DIR__.'/../../../fixtures/empty.gif'; + $path = __DIR__.'/../../fixtures/empty.gif'; $originalName = 'Test.gif'; - $symfonyUploadedFile = new Symfony\Component\HttpFoundation\File\UploadedFile($path, $originalName, null, null, null, true); + $symfonyUploadedFile = new SymfonyUploadedFile($path, $originalName, null, null, null, true); - return new Codesleeve\Stapler\File\UploadedFile($symfonyUploadedFile); + return new UploadedFile($symfonyUploadedFile); } /** * Helper method to build a mock Image object. - * - * @param integer $originalSize - * @param integer $expectedResize - * @param integer $expectedCropPoint - * @param integer $expectedCropBox - * @return Image + * + * @param integer $originalSize + * @param integer $expectedResize + * @param integer $expectedCropPoint + * @param integer $expectedCropBox + * @return Image */ - protected function mockImage($originalSize, $expectedResize, $expectedCropPoint = null, $expectedCropBox = null) + protected function mockImage($originalSize, $expectedResize, $expectedCropPoint = null, $expectedCropBox = null) { $image = $this->getMock('Image', ['getSize', 'resize', 'crop', 'save']); @@ -91,17 +94,17 @@ protected function mockImage($originalSize, $expectedResize, $expectedCropPoint $image->expects($this->once()) ->method('save'); - + return $image; } /** * Helper method to build a mock Imagine instance. - * - * @param Image $image + * + * @param Image $image * @return Imagine */ - protected function mockImageProcessor($image) + protected function mockImageProcessor($image) { $imageProcessor = $this->getMock('Imagine', ['open']); @@ -116,10 +119,10 @@ protected function mockImageProcessor($image) * Helper method to build a mock style object. * * @param string $name - * @param string $value - * @return Object + * @param string $value + * @return Object */ - protected function styleObject($name, $value) + protected function styleObject($name, $value) { $style = new stdClass; $style->name = $name; diff --git a/tests/Stapler/File/UploadedFileTest.php b/tests/Codesleeve/Stapler/File/UploadedFileTest.php similarity index 70% rename from tests/Stapler/File/UploadedFileTest.php rename to tests/Codesleeve/Stapler/File/UploadedFileTest.php index e877c00..6d7441c 100644 --- a/tests/Stapler/File/UploadedFileTest.php +++ b/tests/Codesleeve/Stapler/File/UploadedFileTest.php @@ -1,13 +1,16 @@ -buildValidStaplerUploadedFile(); - + $staplerUploadedFile->validate(); } /** * Test that the validate method will throw an exception * when passed an invalid file upload object. - * + * * @expectedException Codesleeve\Stapler\Exceptions\FileException * @return void */ public function testValidateThrowsExceptions() { $staplerUploadedFile = $this->buildInvalidStaplerUploadedFile(); - + $staplerUploadedFile->validate(); } /** - * Helper method to build an valid Codesleeve\Stapler\File\UploadedFile object. - * + * Helper method to build an valid Codesleeve\Stapler\File\UploadedFile object. + * * @return UploadedFile */ public function buildValidStaplerUploadedFile() { $symfonyUploadedFile = $this->buildSymfonyUploadedFile(); - - return new Codesleeve\Stapler\File\UploadedFile($symfonyUploadedFile); + + return new UploadedFile($symfonyUploadedFile); } /** - * Helper method to build an invalid Codesleeve\Stapler\File\UploadedFile object. - * + * Helper method to build an invalid Codesleeve\Stapler\File\UploadedFile object. + * * @return UploadedFile */ public function buildInvalidStaplerUploadedFile() { $symfonyUploadedFile = $this->buildSymfonyUploadedFile(false); - - return new Codesleeve\Stapler\File\UploadedFile($symfonyUploadedFile); + + return new UploadedFile($symfonyUploadedFile); } /** * Helper method to build a mock Symfony UploadedFile object. * * @param boolean $test - * @return UploadedFile + * @return UploadedFile */ - protected function buildSymfonyUploadedFile($test = true) + protected function buildSymfonyUploadedFile($test = true) { - $path = __DIR__.'/../../fixtures/empty.gif'; + $path = __DIR__.'/../fixtures/empty.gif'; $originalName = 'Test.gif'; - - return new Symfony\Component\HttpFoundation\File\UploadedFile($path, $originalName, null, null, null, $test); + + return new SymfonyUploadedFile($path, $originalName, null, null, null, $test); } } \ No newline at end of file diff --git a/tests/fixtures/empty.gif b/tests/Codesleeve/Stapler/Fixtures/empty.gif similarity index 100% rename from tests/fixtures/empty.gif rename to tests/Codesleeve/Stapler/Fixtures/empty.gif diff --git a/tests/Stapler/InterpolatorTest.php b/tests/Codesleeve/Stapler/InterpolatorTest.php similarity index 94% rename from tests/Stapler/InterpolatorTest.php rename to tests/Codesleeve/Stapler/InterpolatorTest.php index fa1be05..d9b9cbc 100644 --- a/tests/Stapler/InterpolatorTest.php +++ b/tests/Codesleeve/Stapler/InterpolatorTest.php @@ -1,13 +1,13 @@ -shouldReceive('getKey')->twice()->andReturn(1); - + $config = m::mock('Codesleeve\Stapler\Config', ['bar', ['default_style' => 'original']]); $attachment = m::mock('Codesleeve\Stapler\Attachment[originalFilename, getInstanceClass]'); diff --git a/tests/TestCase.php b/tests/Codesleeve/Stapler/TestCase.php similarity index 60% rename from tests/TestCase.php rename to tests/Codesleeve/Stapler/TestCase.php index b278f0c..fedc85c 100644 --- a/tests/TestCase.php +++ b/tests/Codesleeve/Stapler/TestCase.php @@ -1,8 +1,9 @@ -instance('app', $app); $app->register('Codesleeve\Stapler\StaplerServiceProvider'); - Illuminate\Support\Facades\Facade::setFacadeApplication($app); + Facade::setFacadeApplication($app); } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..703cbb4 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,6 @@ +add('Codesleeve\Stapler\\', __DIR__); + +date_default_timezone_set('UTC');