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>
<tr> <tr>
<td>Another content</td> <td>Another content</td>
<td></td> <td>Lorem ipsum</td>
<td><span class="text-danger">{{ m.icon('x-lg') }}</span></td> <td><span class="text-danger">{{ m.icon('x-lg') }}</span></td>
</tr> </tr>
</table> </table>

View File

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

View File

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

View File

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