forked from biblioverse/biblioteca
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(kobo): Better injection of filesystem manager
- Loading branch information
Showing
12 changed files
with
73 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace App\Service; | ||
|
||
use App\Entity\Book; | ||
|
||
interface BookFileSystemManagerInterface | ||
{ | ||
public function getBooksDirectory(): string; | ||
|
||
public function getCoverDirectory(): string; | ||
|
||
public function getBookFilename(Book $book): string; | ||
|
||
public function getBookPublicPath(Book $book): string; | ||
|
||
public function getCoverFilename(Book $book): ?string; | ||
|
||
public function getBookSize(Book $book): ?int; | ||
|
||
public function getCoverSize(Book $book): ?int; | ||
|
||
public function fileExist(Book $book): bool; | ||
|
||
public function coverExist(Book $book): bool; | ||
|
||
public function getBookFile(Book $book): \SplFileInfo; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
namespace App\Tests; | ||
|
||
use App\Service\BookFileSystemManager; | ||
use Psr\Log\LoggerInterface; | ||
use Symfony\Bundle\SecurityBundle\Security; | ||
use Symfony\Component\String\Slugger\SluggerInterface; | ||
|
||
class FileSystemManagerForTests extends BookFileSystemManager | ||
{ | ||
public function __construct( | ||
Security $security, | ||
SluggerInterface $slugger, | ||
LoggerInterface $logger, | ||
protected string $publicDirectory, | ||
){ | ||
parent::__construct( | ||
$security, | ||
$publicDirectory, | ||
'{authorFirst}/{author}/{serie}/{title}', | ||
'{serie}-{serieIndex}-{title}', | ||
$slugger, | ||
$logger | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,8 @@ | ||
<?php | ||
namespace App\Tests; | ||
|
||
use App\DataFixtures\BookFixture; | ||
use App\Service\BookFileSystemManager; | ||
use Psr\Log\NullLogger; | ||
use Symfony\Bundle\SecurityBundle\Security; | ||
use Symfony\Component\String\Slugger\SluggerInterface; | ||
|
||
trait InjectFakeFileSystemTrait | ||
{ | ||
public function injectFakeFileSystemManager(): void | ||
{ | ||
$resources = __DIR__.'/Resources'; | ||
$realPath = realpath($resources); | ||
self::assertNotFalse($realPath); | ||
$fixtureBookPath = $realPath."/"; | ||
$mockBuilder = $this->getMockBuilder(BookFileSystemManager::class); | ||
|
||
$DEFAULT_BOOK_FOLDER_NAMING_FORMAT = '{authorFirst}/{author}/{title}/{serie}'; | ||
$DEFAULT_BOOK_FILE_NAMING_FORMAT = '{serie}-{title}'; | ||
|
||
$mock = $mockBuilder->setConstructorArgs([ | ||
self::getContainer()->get(Security::class), | ||
realpath($resources), | ||
$DEFAULT_BOOK_FOLDER_NAMING_FORMAT, | ||
$DEFAULT_BOOK_FILE_NAMING_FORMAT, | ||
$this->createMock(SluggerInterface::class), | ||
new NullLogger(), | ||
]) | ||
->onlyMethods(['getBooksDirectory', 'getCoverDirectory']) | ||
->enableProxyingToOriginalMethods() | ||
->getMock(); | ||
$mock->expects(self::any())->method('getBooksDirectory')->willReturn($fixtureBookPath); | ||
$mock->expects(self::any())->method('getCoverDirectory')->willReturn($fixtureBookPath); | ||
|
||
self::assertSame(realpath($resources).'/books/'.BookFixture::BOOK_ODYSSEY_FILENAME, $mock->getBookFilename($this->getBook()), "Faking Filesystem failed"); | ||
self::getContainer()->set(BookFileSystemManager::class, $mock); | ||
} | ||
{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters