Skip to content

Commit

Permalink
Move phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
jissereitsma committed Feb 27, 2022
1 parent b3529e1 commit 8302864
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
phpstan.neon
15 changes: 13 additions & 2 deletions Convertor/ConvertorListing.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,26 @@ class ConvertorListing
/**
* @var ConvertorInterface[]
*/
private $convertors;
private $convertors = [];

/**
* ConvertorListing constructor.
* @param ConvertorInterface[] $convertors
*/
public function __construct(array $convertors = [])
{
$this->convertors = $convertors;
foreach ($convertors as $convertor) {
$this->addConvertor($convertor);
}
}

/**
* @param ConvertorInterface $convertor
* @return void
*/
public function addConvertor(ConvertorInterface $convertor)
{
$this->convertors[] = $convertor;
}

/**
Expand Down
8 changes: 7 additions & 1 deletion Test/Integration/Util/UrlConvertorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Yireo\NextGenImages\Test\Integration\Util;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\UrlInterface;
use Magento\Framework\View\Asset\File\NotFoundException;
use Yireo\IntegrationTestHelper\Test\Integration\AbstractTestCase;
use Yireo\NextGenImages\Util\UrlConvertor;
Expand All @@ -13,6 +15,7 @@ public function testGetUrlFromFilename()
{
$directoryList = $this->objectManager->get(DirectoryList::class);
$root = $directoryList->getRoot();

$urlConvertor = $this->objectManager->create(UrlConvertor::class);

$filename = $urlConvertor->getFilenameFromUrl('/static/foobar.jpg');
Expand All @@ -22,6 +25,9 @@ public function testGetUrlFromFilename()
$this->assertSame($root . '/pub/static/foobar.jpg', $filename);
}

/**
* @return void
*/
public function testGetFilenameFromUrl()
{
$directoryList = $this->objectManager->get(DirectoryList::class);
Expand All @@ -30,7 +36,7 @@ public function testGetFilenameFromUrl()
$urlConvertor = $this->objectManager->create(UrlConvertor::class);
$filename = $urlConvertor->getUrlFromFilename($root . '/pub/static/foobar.jpg');

$expectedUrl = 'http://localhost/index.php/static/foobar.jpg';
$expectedUrl = 'http://localhost/static/foobar.jpg';

$this->assertSame($expectedUrl, $filename);
}
Expand Down
9 changes: 9 additions & 0 deletions Test/Unit/Convertor/ConvertorListingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Yireo\NextGenImages\Test\Unit\Convertor;

use PHPUnit\Framework\TestCase;
use TypeError;
use Yireo\NextGenImages\Convertor\ConvertorInterface;
use Yireo\NextGenImages\Convertor\ConvertorListing;

Expand All @@ -22,4 +23,12 @@ public function testGetConvertorsWithOneConvertor()

$this->assertEquals(1, count($convertorListing->getConvertors()));
}

public function testWithInvalidConvertorShouldFail()
{
$this->expectException(TypeError::class);
new ConvertorListing([
'this-should-not-work'
]);
}
}
2 changes: 1 addition & 1 deletion Util/UrlConvertor.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function getFilenameFromUrl(string $url): string
*/
private function getBaseUrl(): string
{
return str_replace('/index.php/', '', $this->urlModel->getBaseUrl());
return str_replace('/index.php/', '/', $this->urlModel->getBaseUrl());
}

/**
Expand Down
File renamed without changes.

0 comments on commit 8302864

Please sign in to comment.