Skip to content
Permalink
Browse files

Made all PHPUnit tests pass

  • Loading branch information...
christeredvartsen committed Sep 12, 2019
1 parent 1e81fa2 commit 0146eb6cef33efb33b481f26945cfc4674bc10f0
@@ -15,13 +15,13 @@
Imbo\Resource\Images\Query,
Imbo\Exception\DatabaseException,
Imbo\Exception\DuplicateImageIdentifierException,
Imbo\Exception\InvalidArgumentException,
Imbo\Helpers\BSONToArray,
MongoDB\Client as MongoClient,
MongoDB\Driver\Manager,
MongoDB\Driver\Command,
MongoDB\Collection as MongoCollection,
MongoDB\Driver\Exception\Exception as MongoException,
MongoDB\Model\BSONDocument,
DateTime,
DateTimeZone;
@@ -506,16 +506,14 @@ public function getNumBytes($user = null) {
]);
}
$result = $this->getImageCollection()->aggregate($pipeline, ['useCursor' => false]);
if (!count($result)) {
return 0;
}
return (int) $result[0]->numBytes;
$docs = $this->getImageCollection()->aggregate($pipeline)->toArray();
} catch (MongoException $e) {
throw new DatabaseException('Unable to fetch information from the database', 500, $e);
}
return empty($docs) ? 0 : array_sum(array_map(function(BSONDocument $doc) : int {
return $doc->numBytes;
}, $docs));
}
/**
@@ -208,10 +208,12 @@ public function testDoesNotSetResponseContentWhenHttpMethodIsHead() {
public function testThrowsAnExceptionInStrictModeWhenTheUserAgentDoesNotSupportAnyOfImbosMediaTypes() {
$this->contentNegotiation->expects($this->any())->method('isAcceptable')->will($this->returnValue(false));
$this->response->expects($this->once())->method('setVary')->with('Accept');
$this->response->expects($this->once())->method('getModel')->willReturn($this->createMock(Image::class));
$requestHeaders = $this->createMock('Symfony\Component\HttpFoundation\HeaderBag');
$requestHeaders->expects($this->once())->method('get')->with('Accept', '*/*')->will($this->returnValue('text/xml'));
$this->request->headers = $requestHeaders;
$this->expectExceptionObject(new RuntimeException('Not acceptable', 406));
$this->responseFormatter->negotiate($this->event);
}
@@ -225,6 +227,7 @@ public function testUsesDefaultMediaTypeInNonStrictModeWhenTheUserAgentDoesNotSu
$this->request->headers = $requestHeaders;
$this->contentNegotiation->expects($this->any())->method('isAcceptable')->will($this->returnValue(false));
$this->response->expects($this->once())->method('setVary')->with('Accept');
$this->response->expects($this->once())->method('getModel')->willReturn($this->createMock(Image::class));
$this->responseFormatter->negotiate($this->event);
$this->assertSame('json', $this->responseFormatter->getFormatter());
@@ -239,6 +242,7 @@ public function testPicksThePrioritizedMediaTypeIfMoreThanOneWithSameQualityAreS
$this->request->headers = $requestHeaders;
$this->contentNegotiation->expects($this->any())->method('isAcceptable')->will($this->returnValue(1));
$this->response->expects($this->once())->method('setVary')->with('Accept');
$this->response->expects($this->once())->method('getModel')->willReturn($this->createMock(Image::class));
$this->responseFormatter->negotiate($this->event);
$this->assertSame('json', $this->responseFormatter->getFormatter());
@@ -11,8 +11,6 @@
namespace ImboUnitTest\Http\Response;
use Imbo\Http\Response\Response;
use Imbo\Exception;
use Imbo\Exception\RuntimeException;
use DateTime;
use DateTimeZone;
use PHPUnit\Framework\TestCase;
@@ -40,26 +40,6 @@ public function testThrowsExceptionOnMissingLevelParameter() {
$this->transformation->transform([]);
}
public function testDoesNotApplyCompressionToGifImages() {
$image = $this->createMock('Imbo\Model\Image');
$image->expects($this->once())->method('getMimeType')->will($this->returnValue('image/gif'));
$imagick = $this->createMock('Imagick');
$imagick->expects($this->never())->method('setImageCompressionQuality');
$this->transformation->setImagick($imagick)->setImage($image)->transform(['level' => 40]);
$this->transformation->compress($this->createMock('Imbo\EventManager\EventInterface'));
}
public function testDoesNotApplyCompressionWhenLevelIsNotSet() {
$imagick = $this->createMock('Imagick');
$imagick->expects($this->never())->method('setImageCompressionQuality');
$this->transformation->setImagick($imagick)->compress(
$this->createMock('Imbo\EventManager\Event')
);
}
public function testThrowsExceptionOnInvalidLevel() {
$this->expectExceptionObject(new TransformationException(
'level must be between 0 and 100',
@@ -13,7 +13,7 @@
use Imbo\Resource\Image;
/**
* @covers Imbo\Resource\Image
* @coversDefaultClass Imbo\Resource\Image
* @group unit
* @group resources
*/
@@ -17,7 +17,7 @@
use DateTimeZone;
/**
* @covers Imbo\Resource\Images
* @coversDefaultClass Imbo\Resource\Images
* @group unit
* @group resources
*/
@@ -13,7 +13,7 @@
use Imbo\Resource\Index;
/**
* @covers Imbo\Resource\Index
* @coversDefaultClass Imbo\Resource\Index
* @group unit
* @group resources
*/
@@ -16,7 +16,7 @@
use DateTimeZone;
/**
* @covers Imbo\Resource\Metadata
* @coversDefaultClass Imbo\Resource\Metadata
* @group unit
* @group resources
*/
@@ -10,8 +10,6 @@
namespace ImboUnitTest\Resource;
use ReflectionClass;
use ReflectionMethod;
use PHPUnit\Framework\TestCase;
/**
@@ -14,7 +14,7 @@
use Imbo\Exception\ResourceException;
/**
* @covers Imbo\Resource\ShortUrl
* @coversDefaultClass Imbo\Resource\ShortUrl
* @group unit
* @group resources
*/
@@ -14,7 +14,7 @@
use Imbo\Exception\InvalidArgumentException;
/**
* @covers Imbo\Resource\ShortUrls
* @coversDefaultClass Imbo\Resource\ShortUrls
* @group unit
* @group resources
*/
@@ -13,7 +13,7 @@
use Imbo\Resource\Stats;
/**
* @covers Imbo\Resource\Stats
* @coversDefaultClass Imbo\Resource\Stats
* @group unit
* @group resources
*/
@@ -13,7 +13,7 @@
use Imbo\Resource\Status;
/**
* @covers Imbo\Resource\Status
* @coversDefaultClass Imbo\Resource\Status
* @group unit
* @group resources
*/
@@ -15,7 +15,7 @@
use DateTimeZone;
/**
* @covers Imbo\Resource\User
* @coversDefaultClass Imbo\Resource\User
* @group unit
* @group resources
*/

0 comments on commit 0146eb6

Please sign in to comment.
You can’t perform that action at this time.