Working state but no uploads
This commit is contained in:
@@ -23,6 +23,7 @@ use Tests\ControllerTestCase;
|
||||
* - upload : absence de fichier, erreur PSR-7, exceptions métier (taille, MIME, stockage), succès
|
||||
* - delete : introuvable, non-propriétaire, succès propriétaire, succès admin
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
|
||||
final class MediaControllerTest extends ControllerTestCase
|
||||
{
|
||||
/** @var \Slim\Views\Twig&MockObject */
|
||||
|
||||
@@ -7,6 +7,8 @@ use App\Media\Media;
|
||||
use DateTime;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
|
||||
|
||||
final class MediaModelTest extends TestCase
|
||||
{
|
||||
public function testConstructAndGettersExposeMediaData(): void
|
||||
|
||||
@@ -19,6 +19,7 @@ use PHPUnit\Framework\TestCase;
|
||||
* PDO et PDOStatement sont mockés pour isoler complètement
|
||||
* le dépôt de la base de données.
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
|
||||
final class MediaRepositoryTest extends TestCase
|
||||
{
|
||||
/** @var PDO&MockObject */
|
||||
@@ -258,7 +259,7 @@ final class MediaRepositoryTest extends TestCase
|
||||
$media = Media::fromArray($this->rowImage);
|
||||
$stmt = $this->stmtForWrite();
|
||||
|
||||
$this->db->method('prepare')
|
||||
$this->db->expects($this->once())->method('prepare')
|
||||
->with($this->stringContains('INSERT INTO media'))
|
||||
->willReturn($stmt);
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ use PHPUnit\Framework\TestCase;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
|
||||
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
|
||||
|
||||
final class MediaServiceDuplicateAfterInsertRaceTest extends TestCase
|
||||
{
|
||||
/** @var MediaRepositoryInterface&MockObject */
|
||||
@@ -67,7 +69,7 @@ final class MediaServiceDuplicateAfterInsertRaceTest extends TestCase
|
||||
private function makeUploadedFileFromPath(string $path, int $size): UploadedFileInterface
|
||||
{
|
||||
$stream = $this->createMock(StreamInterface::class);
|
||||
$stream->method('getMetadata')->with('uri')->willReturn($path);
|
||||
$stream->expects($this->once())->method('getMetadata')->with('uri')->willReturn($path);
|
||||
|
||||
$file = $this->createMock(UploadedFileInterface::class);
|
||||
$file->method('getSize')->willReturn($size);
|
||||
|
||||
@@ -11,6 +11,8 @@ use PHPUnit\Framework\TestCase;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
|
||||
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
|
||||
|
||||
final class MediaServiceEdgeCasesTest extends TestCase
|
||||
{
|
||||
public function testRejectsWhenSizeUnknown(): void
|
||||
|
||||
@@ -10,6 +10,8 @@ use PHPUnit\Framework\TestCase;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
|
||||
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
|
||||
|
||||
final class MediaServiceInvalidMimeTest extends TestCase
|
||||
{
|
||||
public function testRejectsNonImageContentEvenWithImageLikeFilename(): void
|
||||
@@ -21,7 +23,7 @@ final class MediaServiceInvalidMimeTest extends TestCase
|
||||
file_put_contents($tmpFile, 'not an image');
|
||||
|
||||
$stream = $this->createMock(StreamInterface::class);
|
||||
$stream->method('getMetadata')->with('uri')->willReturn($tmpFile);
|
||||
$stream->expects($this->once())->method('getMetadata')->with('uri')->willReturn($tmpFile);
|
||||
|
||||
$file = $this->createMock(UploadedFileInterface::class);
|
||||
$file->method('getSize')->willReturn(filesize($tmpFile));
|
||||
|
||||
@@ -10,6 +10,8 @@ use PHPUnit\Framework\TestCase;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
|
||||
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
|
||||
|
||||
final class MediaServiceInvalidTempPathTest extends TestCase
|
||||
{
|
||||
public function testRejectsWhenTemporaryPathIsMissing(): void
|
||||
@@ -17,7 +19,7 @@ final class MediaServiceInvalidTempPathTest extends TestCase
|
||||
$repository = $this->createMock(MediaRepositoryInterface::class);
|
||||
|
||||
$stream = $this->createMock(StreamInterface::class);
|
||||
$stream->method('getMetadata')->with('uri')->willReturn(null);
|
||||
$stream->expects($this->once())->method('getMetadata')->with('uri')->willReturn(null);
|
||||
|
||||
$file = $this->createMock(UploadedFileInterface::class);
|
||||
$file->method('getSize')->willReturn(128);
|
||||
|
||||
@@ -27,6 +27,7 @@ use Psr\Http\Message\UploadedFileInterface;
|
||||
* - stockage : fichier écrit sur disque, media créé en base
|
||||
* - suppression : fichier supprimé du disque et entrée retirée de la base
|
||||
*/
|
||||
#[\PHPUnit\Framework\Attributes\AllowMockObjectsWithoutExpectations]
|
||||
final class MediaServiceTest extends TestCase
|
||||
{
|
||||
/** @var MediaRepositoryInterface&MockObject */
|
||||
@@ -196,7 +197,7 @@ final class MediaServiceTest extends TestCase
|
||||
public function testFindByIdReturnsMedia(): void
|
||||
{
|
||||
$media = new Media(3, 'photo.jpg', '/media/photo.jpg', 'abc123', 1);
|
||||
$this->repository->method('findById')->with(3)->willReturn($media);
|
||||
$this->repository->expects($this->once())->method('findById')->with(3)->willReturn($media);
|
||||
|
||||
$this->assertSame($media, $this->service->findById(3));
|
||||
}
|
||||
@@ -210,7 +211,7 @@ final class MediaServiceTest extends TestCase
|
||||
private function makeUploadedFile(int $size): UploadedFileInterface
|
||||
{
|
||||
$stream = $this->createMock(StreamInterface::class);
|
||||
$stream->method('getMetadata')->with('uri')->willReturn('/nonexistent/path');
|
||||
$stream->method('getMetadata')->willReturnMap([['uri', '/nonexistent/path']]);
|
||||
|
||||
$file = $this->createMock(UploadedFileInterface::class);
|
||||
$file->method('getSize')->willReturn($size);
|
||||
@@ -226,7 +227,7 @@ final class MediaServiceTest extends TestCase
|
||||
private function makeUploadedFileFromPath(string $path, int $size): UploadedFileInterface
|
||||
{
|
||||
$stream = $this->createMock(StreamInterface::class);
|
||||
$stream->method('getMetadata')->with('uri')->willReturn($path);
|
||||
$stream->method('getMetadata')->willReturnMap([['uri', $path]]);
|
||||
|
||||
$file = $this->createMock(UploadedFileInterface::class);
|
||||
$file->method('getSize')->willReturn($size);
|
||||
|
||||
Reference in New Issue
Block a user