Cleanup duplicated app calls, replaced deprecated methods, readability improvements

This commit is contained in:
Igor Scheller 2022-07-11 23:22:22 +02:00
parent 006dde9d8e
commit c957b2784a
4 changed files with 18 additions and 15 deletions

View File

@ -94,7 +94,7 @@
</tr>
<tr>
<td>Another content</td>
<td></td>
<td>Lorem ipsum</td>
<td><span class="text-danger">{{ m.icon('x-lg') }}</span></td>
</tr>
</table>

View File

@ -2,7 +2,6 @@
namespace Engelsystem\Test\Unit\Controllers;
use Engelsystem\Application;
use Engelsystem\Config\Config;
use Engelsystem\Controllers\DesignController;
use Engelsystem\Http\Response;
@ -16,7 +15,6 @@ class DesignControllerTest extends TestCase
parent::setUp();
$this->mockRenderer();
$this->mockTranslator();
Application::setInstance($this->app);
}
/**

View File

@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Engelsystem\Test\Unit\Helpers;
use Engelsystem\Application;
use Engelsystem\Helpers\BarChart;
use Engelsystem\Renderer\Renderer;
use Engelsystem\Test\Unit\TestCase;
@ -38,12 +37,6 @@ class BarChartTest extends TestCase
parent::setUp();
$this->rendererMock = $this->mockRenderer(false);
$this->mockTranslator();
Application::setInstance($this->app);
}
protected function tearDown(): void
{
Application::setInstance(null);
}
public function testRender(): void

View File

@ -3,6 +3,7 @@
namespace Engelsystem\Test\Unit;
use Engelsystem\Application;
use Engelsystem\Helpers\Translation\Translator;
use Engelsystem\Renderer\Renderer;
use Faker\Factory as FakerFactory;
use Faker\Generator;
@ -58,15 +59,25 @@ abstract class TestCase extends PHPUnitTestCase
$this->app->instance(Generator::class, $faker);
}
protected function mockTranslator(): void
/**
* @param bool $mockImplementation
* @return Translator&MockObject
*/
protected function mockTranslator(bool $mockImplementation = true): Translator
{
$translator = $this->getMockBuilder(Translator::class)
->disableOriginalConstructor()
->setMethods(['translate'])
->onlyMethods(['translate'])
->getMock();
if ($mockImplementation) {
$translator->method('translate')
->willReturnCallback(fn(string $key, array $replace = []) => $key);
}
$this->app->instance('translator', $translator);
return $translator;
}
/**
@ -77,7 +88,7 @@ abstract class TestCase extends PHPUnitTestCase
{
$renderer = $this->getMockBuilder(Renderer::class)
->disableOriginalConstructor()
->setMethods(['render'])
->onlyMethods(['render'])
->getMock();
if ($mockImplementation) {
@ -86,6 +97,7 @@ abstract class TestCase extends PHPUnitTestCase
}
$this->app->instance('renderer', $renderer);
return $renderer;
}
}