for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Wambo\Core;
use League\Flysystem\Filesystem;
use League\Flysystem\Memory\MemoryAdapter;
use PHPUnit\Framework\TestCase;
use Slim\Container;
use Wambo\Core\Module\JSONModuleStorage;
use Wambo\Core\Module\ModuleMapper;
use Wambo\Core\Module\ModuleRepository;
/**
* Class DITest contains DI Tests
*
* @package Wambo\Core
*/
class DITest extends TestCase
{
* @test
public function testDIinApp()
// arrange
$container = new Container();
$container['filesystem_adapter'] = function($c) { return new MemoryAdapter(); };
$c
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.
$container['filesystem'] = function($c) { return new Filesystem($c['filesystem_adapter']); };
$container['module_repository'] = function($c) {
$storage = new JSONModuleStorage($c['filesystem'], 'modules.json');
$mapper = new ModuleMapper();
return new ModuleRepository($storage, $mapper);
};
$app = new App($container);
$container
object<Slim\Container>
string
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example:
function acceptsInteger($int) { } $x = '123'; // string "123" // Instead of acceptsInteger($x); // we recommend to use acceptsInteger((integer) $x);
// act
$filesystem = $app->getContainer()->get('filesystem');
$hasFile = $filesystem->has('notExistingFile.txt');
// assert
$this->assertFalse($hasFile);
}
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.