| 1 | <?php |
||
| 2 | |||
| 3 | namespace Azine\HybridAuthBundle\Tests\Controller; |
||
| 4 | |||
| 5 | use Doctrine\ORM\EntityManager; |
||
|
0 ignored issues
–
show
|
|||
| 6 | use Symfony\Bundle\FrameworkBundle\Client; |
||
| 7 | use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
||
| 8 | use Symfony\Component\DependencyInjection\ContainerInterface; |
||
| 9 | use Symfony\Component\DomCrawler\Crawler; |
||
|
0 ignored issues
–
show
The type
Symfony\Component\DomCrawler\Crawler was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 10 | use Symfony\Component\EventDispatcher\EventDispatcher; |
||
| 11 | use Symfony\Component\Routing\Generator\UrlGeneratorInterface; |
||
| 12 | |||
| 13 | class AzineHybridAuthJsonControllerTest extends WebTestCase |
||
| 14 | { |
||
| 15 | public function testJsonResponse() |
||
| 16 | { |
||
| 17 | $this->checkApplication(); |
||
| 18 | } |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Load the url and login if required. |
||
| 22 | * |
||
| 23 | * @param string $url |
||
| 24 | * @param string $username |
||
| 25 | * @param Client $client |
||
| 26 | * |
||
| 27 | * @return Crawler $crawler of the page of the url or the page after the login |
||
| 28 | */ |
||
| 29 | private function loginUserIfRequired(Client $client, $url, $username = 'dominik', $password = 'lkjlkjlkjlkj') |
||
|
0 ignored issues
–
show
|
|||
| 30 | { |
||
| 31 | // try to get the url |
||
| 32 | $client->followRedirects(); |
||
| 33 | $crawler = $client->request('GET', $url); |
||
| 34 | |||
| 35 | $this->assertSame(200, $client->getResponse()->getStatusCode(), 'Status-Code 200 expected.'); |
||
| 36 | |||
| 37 | // if redirected to a login-page, login as admin-user |
||
| 38 | if (5 == $crawler->filter('input')->count() && 1 == $crawler->filter('#username')->count() && 1 == $crawler->filter('#password')->count()) { |
||
| 39 | // set the password of the admin |
||
| 40 | $userProvider = $this->getContainer()->get('fos_user.user_provider.username_email'); |
||
| 41 | $user = $userProvider->loadUserByUsername($username); |
||
| 42 | $user->setPlainPassword($password); |
||
| 43 | $user->addRole('ROLE_ADMIN'); |
||
| 44 | |||
| 45 | $userManager = $this->getContainer()->get('fos_user.user_manager'); |
||
| 46 | $userManager->updateUser($user); |
||
| 47 | |||
| 48 | $crawler = $crawler->selectButton('Login'); |
||
| 49 | $form = $crawler->form(); |
||
| 50 | $form->get('_username')->setValue($username); |
||
| 51 | $form->get('_password')->setValue($password); |
||
| 52 | $crawler = $client->submit($form); |
||
| 53 | } |
||
| 54 | |||
| 55 | $this->assertSame(200, $client->getResponse()->getStatusCode(), 'Login failed.'); |
||
| 56 | $client->followRedirects(false); |
||
| 57 | |||
| 58 | $this->assertStringEndsWith($url, $client->getRequest()->getUri(), "Login failed or not redirected to requested url: $url vs. ".$client->getRequest()->getUri()); |
||
| 59 | |||
| 60 | return $crawler; |
||
| 61 | } |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @var ContainerInterface |
||
| 65 | */ |
||
| 66 | private $appContainer; |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Get the current container. |
||
| 70 | * |
||
| 71 | * @return \Symfony\Component\DependencyInjection\ContainerInterface |
||
| 72 | */ |
||
| 73 | private function getContainer() |
||
| 74 | { |
||
| 75 | if (null == $this->appContainer) { |
||
| 76 | $this->appContainer = static::$kernel->getContainer(); |
||
| 77 | } |
||
| 78 | |||
| 79 | return $this->appContainer; |
||
| 80 | } |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @return UrlGeneratorInterface |
||
| 84 | */ |
||
| 85 | private function getRouter() |
||
|
0 ignored issues
–
show
|
|||
| 86 | { |
||
| 87 | return $this->getContainer()->get('router'); |
||
| 88 | } |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @return EntityManager |
||
| 92 | */ |
||
| 93 | private function getEntityManager() |
||
|
0 ignored issues
–
show
|
|||
| 94 | { |
||
| 95 | return $this->getContainer()->get('doctrine.orm.entity_manager'); |
||
| 96 | } |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @return EventDispatcher |
||
| 100 | */ |
||
| 101 | private function getEventDispatcher() |
||
|
0 ignored issues
–
show
|
|||
| 102 | { |
||
| 103 | return $this->getContainer()->get('event_dispatcher'); |
||
| 104 | } |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Check if the current setup is a full application. |
||
| 108 | * If not, mark the test as skipped else continue. |
||
| 109 | */ |
||
| 110 | private function checkApplication() |
||
| 111 | { |
||
| 112 | try { |
||
| 113 | static::$kernel = static::createKernel(array()); |
||
| 114 | } catch (\RuntimeException $ex) { |
||
| 115 | $this->markTestSkipped('There does not seem to be a full application available (e.g. running tests on travis.org). So this test is skipped.'); |
||
| 116 | |||
| 117 | return; |
||
| 118 | } |
||
| 119 | } |
||
| 120 | } |
||
| 121 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths