У меня проблемы с попыткой входа на тестирование.Следуя документации, я сделал это так:
private function logIn()
{
$session = $this->client->getContainer()->get('session');
$firewallName = 'main';
// if you don't define multiple connected firewalls, the context defaults to the firewall name
// See https://symfony.com/doc/current/reference/configuration/security.html#firewall-context
$firewallContext = 'main';
// you may need to use a different token class depending on your application.
// for example, when using Guard authentication you must instantiate PostAuthenticationGuardToken
$token = new UsernamePasswordToken('login', 'password&', $firewallName, array('ROLE_ADMIN'));
$session->set('_security_'.$firewallContext, serialize($token));
$session->save();
$cookie = new Cookie($session->getName(), $session->getId());
$this->client->getCookieJar()->set($cookie);
}
Затем в своей функции тестирования я вызываю функцию входа в систему, запрашиваю личную страницу веб-сайта, но она не работает.Когда я печатаю сканер, я вижу, что что-то не так.
$this->logIn($encoder);
$crawler = $this->client->request('GET', '/projects');
var_dump($crawler);
die();
Вот пример того, что я получаю в инструменте cmd:
PDOException:
SQLSTATE[08006] [7] fe_sendauth: no password supplied
at vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php:46
at PDO->__construct('pgsql:host=localhost;dbname=;', 'root', null, array())
(vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOConnection.php:46)
at Doctrine\DBAL\Driver\PDOConnection->__construct('pgsql:host=localhost;dbname=;', 'root', null, array())
(vendor\doctrine\dbal\lib\Doctrine\DBAL\Driver\PDOPgSql\Driver.php:46)
at Doctrine\DBAL\Driver\PDOPgSql\Driver->connect(array('driver' => 'pdo_pgsql', 'charset' => 'utf8', 'url' => '', 'host' => 'localhost', 'port' => null, 'user' => 'root', 'password' => null, 'driverOptions' => array(), 'serverVersion' => '10.2', 'defaultTableOptions' => array('charset' => 'utf8', 'collate' => 'utf8_unicode_ci'), 'dbname' => ''), 'root', null, array())
(vendor\doctrine\dbal\lib\Doctrine\DBAL\Connection.php:389)
at Doctrine\DBAL\Connection->connect()
(vendor\doctrine\dbal\lib\Doctrine\DBAL\Connection.php:921)
at Doctrine\DBAL\Connection->executeQuery('SELECT t0.id AS id_1, t0.name AS name_2, t0.looking_date AS looking_date_3, t0.output AS output_4, t0.updated_at AS updated_at_5, t0.created_at AS created_at_6, t0.owner_id AS owner_id_7 FROM project t0', array(), array())
(vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\Entity\BasicEntityPersister.php:904)
at Doctrine\ORM\Persisters\Entity\BasicEntityPersister->loadAll(array(), null, null, null)
(vendor\doctrine\orm\lib\Doctrine\ORM\EntityRepository.php:181)
at Doctrine\ORM\EntityRepository->findBy(array())
(vendor\doctrine\orm\lib\Doctrine\ORM\EntityRepository.php:164)
at Doctrine\ORM\EntityRepository->findAll()
(src\Controller\ProjectController.php:49)
at App\Controller\ProjectController->projectList('projectList')
(vendor\symfony\http-kernel\HttpKernel.php:149)
at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
(vendor\symfony\http-kernel\HttpKernel.php:66)
at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
(vendor\symfony\http-kernel\Kernel.php:188)
at Symfony\Component\HttpKernel\Kernel->handle(object(Request), 1, true)
(vendor\symfony\http-kernel\Client.php:68)
at Symfony\Component\HttpKernel\Client->doRequest(object(Request))
(vendor\symfony\framework-bundle\Client.php:131)
at Symfony\Bundle\FrameworkBundle\Client->doRequest(object(Request))
(vendor\symfony\browser-kit\Client.php:351)
at Symfony\Component\BrowserKit\Client->request('GET', 'http://localhost/projects')
(tests\Controller\BackendControllerTest.php:51)
at App\Tests\Util\BackendControllerTest->testHomepage()
at ReflectionMethod->invokeArgs(object(BackendControllerTest), array())
(bin\.phpunit\phpunit-6.5\src\Framework\TestCase.php:1071)
at PHPUnit\Framework\TestCase->runTest()
(bin\.phpunit\phpunit-6.5\src\Framework\TestCase.php:939)
at PHPUnit\Framework\TestCase->runBare()
(bin\.phpunit\phpunit-6.5\src\Framework\TestResult.php:698)
at PHPUnit\Framework\TestResult->run(object(BackendControllerTest))
(bin\.phpunit\phpunit-6.5\src\Framework\TestCase.php:894)
at PHPUnit\Framework\TestCase->run(object(TestResult))
(bin\.phpunit\phpunit-6.5\src\Framework\TestSuite.php:755)
at PHPUnit\Framework\TestSuite->run(object(TestResult))
(bin\.phpunit\phpunit-6.5\src\Framework\TestSuite.php:755)
at PHPUnit\Framework\TestSuite->run(object(TestResult))
(bin\.phpunit\phpunit-6.5\src\TextUI\TestRunner.php:545)
at PHPUnit\TextUI\TestRunner->doRun(object(TestSuite), array('listGroups' => false, 'listSuites' => false, 'listTests' => false, 'listTestsXml' => false, 'loader' => null, 'useDefaultConfiguration' => true, 'loadedExtensions' => array(), 'notLoadedExtensions' => array(), 'colors' => 'always', 'testSuffixes' => array('Test.php', '.phpt'), 'configuration' => object(Configuration), 'debug' => false, 'filter' => false, 'listeners' => array(object(SymfonyTestsListenerForV6)), 'backupGlobals' => false, 'bootstrap' => 'C:\\cygwin64\\home\\www\\navitia-tools\\vendor/autoload.php', 'testdoxGroups' => array(), 'testdoxExcludeGroups' => array(), 'addUncoveredFilesFromWhitelist' => true, 'backupStaticAttributes' => null, 'beStrictAboutChangesToGlobalState' => null, 'beStrictAboutResourceUsageDuringSmallTests' => false, 'cacheTokens' => false, 'columns' => 80, 'convertDeprecationsToExceptions' => true, 'convertErrorsToExceptions' => true, 'convertNoticesToExceptions' => true, 'convertWarningsToExceptions' => true, 'crap4jThreshold' => 30, 'disallowTestOutput' => false, 'disallowTodoAnnotatedTests' => false, 'enforceTimeLimit' => false, 'excludeGroups' => array(), 'failOnRisky' => false, 'failOnWarning' => false, 'groups' => array(), 'processIsolation' => false, 'processUncoveredFilesFromWhitelist' => false, 'registerMockObjectsFromTestArgumentsRecursively' => false, 'repeat' => false, 'reportHighLowerBound' => 90, 'reportLowUpperBound' => 50, 'reportUselessTests' => true, 'reverseList' => false, 'stopOnError' => false, 'stopOnFailure' => false, 'stopOnIncomplete' => false, 'stopOnRisky' => false, 'stopOnSkipped' => false, 'stopOnWarning' => false, 'strictCoverage' => false, 'timeoutForLargeTests' => 60, 'timeoutForMediumTests' => 10, 'timeoutForSmallTests' => 1, 'verbose' => false), true)
(bin\.phpunit\phpunit-6.5\src\TextUI\Command.php:195)
at PHPUnit\TextUI\Command->run(array('./bin/phpunit', '--colors=always'), true)
(bin\.phpunit\phpunit-6.5\src\TextUI\Command.php:148)
at PHPUnit\TextUI\Command::main()
(bin\.phpunit\phpunit-6.5\phpunit:17)
at include('C:\\cygwin64\\home\\www\\navitia-tools\\bin\\.phpunit\\phpunit-6.5\\phpunit')
(vendor\symfony\phpunit-bridge\bin\simple-phpunit:261)
at require('C:\\cygwin64\\home\\www\\navitia-tools\\vendor\\symfony\\phpunit-bridge\\bin\\simple-phpunit')
(bin\phpunit:18)
Мои настройки безопасности, если это может помочь:
security:
encoders:
App\Entity\User:
algorithm: bcrypt
# https://symfony.com/doc/current/security.html#where-do-users-come-from-user-providers
providers:
user:
entity:
class: App\Entity\User
property: username
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
# pattern: ^/
anonymous: ~
provider: user
form_login:
login_path: login
check_path: login
provider: user
logout:
path: /logout
target: /
access_denied_handler: App\Security\AccessDeniedHandler
access_control:
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/, roles: [ROLE_ADMIN, ROLE_USER] }
Также для информации (поскольку ошибка - исключение PDO, я использую базу данных pgsql)
Ваша помощь будет очень приветствоваться,
Спасибо за вашу поддержку,