forked from wallabag/wallabag
PHPStan level 5
This commit is contained in:
@ -5,6 +5,7 @@ namespace Tests\Wallabag\Controller\Api;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Tests\Wallabag\WallabagTestCase;
|
||||
use Wallabag\Entity\Api\Client;
|
||||
use Wallabag\Entity\User;
|
||||
|
||||
class DeveloperControllerTest extends WallabagTestCase
|
||||
{
|
||||
@ -133,7 +134,10 @@ class DeveloperControllerTest extends WallabagTestCase
|
||||
$client = $this->getTestClient();
|
||||
$em = $client->getContainer()->get(EntityManagerInterface::class);
|
||||
$userManager = static::getContainer()->get('fos_user.user_manager');
|
||||
|
||||
$user = $userManager->findUserBy(['username' => $username]);
|
||||
\assert($user instanceof User);
|
||||
|
||||
$apiClient = new Client($user);
|
||||
$apiClient->setName('My app');
|
||||
$apiClient->setAllowedGrantTypes($grantTypes);
|
||||
|
||||
@ -45,7 +45,7 @@ class UserRestControllerTest extends WallabagApiTestCase
|
||||
|
||||
public function testCreateNewUser()
|
||||
{
|
||||
$this->client->getContainer()->get(Config::class)->set('api_user_registration', 1);
|
||||
$this->client->getContainer()->get(Config::class)->set('api_user_registration', '1');
|
||||
$this->client->request('PUT', '/api/user.json', [
|
||||
'username' => 'google',
|
||||
'password' => 'googlegoogle',
|
||||
@ -73,14 +73,14 @@ class UserRestControllerTest extends WallabagApiTestCase
|
||||
|
||||
$this->assertSame('application/json', $this->client->getResponse()->headers->get('Content-Type'));
|
||||
|
||||
$this->client->getContainer()->get(Config::class)->set('api_user_registration', 0);
|
||||
$this->client->getContainer()->get(Config::class)->set('api_user_registration', '0');
|
||||
}
|
||||
|
||||
public function testCreateNewUserWithoutAuthentication()
|
||||
{
|
||||
// create a new client instead of using $this->client to be sure client isn't authenticated
|
||||
$client = $this->createUnauthorizedClient();
|
||||
$client->getContainer()->get(Config::class)->set('api_user_registration', 1);
|
||||
$client->getContainer()->get(Config::class)->set('api_user_registration', '1');
|
||||
$client->request('PUT', '/api/user.json', [
|
||||
'username' => 'google',
|
||||
'password' => 'googlegoogle',
|
||||
@ -109,13 +109,13 @@ class UserRestControllerTest extends WallabagApiTestCase
|
||||
|
||||
$this->assertSame('application/json', $client->getResponse()->headers->get('Content-Type'));
|
||||
|
||||
$client->getContainer()->get(Config::class)->set('api_user_registration', 0);
|
||||
$client->getContainer()->get(Config::class)->set('api_user_registration', '0');
|
||||
}
|
||||
|
||||
public function testCreateNewUserWithExistingEmail()
|
||||
{
|
||||
$client = $this->createUnauthorizedClient();
|
||||
$client->getContainer()->get(Config::class)->set('api_user_registration', 1);
|
||||
$client->getContainer()->get(Config::class)->set('api_user_registration', '1');
|
||||
$client->request('PUT', '/api/user.json', [
|
||||
'username' => 'admin',
|
||||
'password' => 'googlegoogle',
|
||||
@ -138,13 +138,13 @@ class UserRestControllerTest extends WallabagApiTestCase
|
||||
|
||||
$this->assertSame('application/json', $client->getResponse()->headers->get('Content-Type'));
|
||||
|
||||
$client->getContainer()->get(Config::class)->set('api_user_registration', 0);
|
||||
$client->getContainer()->get(Config::class)->set('api_user_registration', '0');
|
||||
}
|
||||
|
||||
public function testCreateNewUserWithTooShortPassword()
|
||||
{
|
||||
$client = $this->createUnauthorizedClient();
|
||||
$client->getContainer()->get(Config::class)->set('api_user_registration', 1);
|
||||
$client->getContainer()->get(Config::class)->set('api_user_registration', '1');
|
||||
$client->request('PUT', '/api/user.json', [
|
||||
'username' => 'facebook',
|
||||
'password' => 'face',
|
||||
@ -162,7 +162,7 @@ class UserRestControllerTest extends WallabagApiTestCase
|
||||
|
||||
$this->assertSame('application/json', $client->getResponse()->headers->get('Content-Type'));
|
||||
|
||||
$client->getContainer()->get(Config::class)->set('api_user_registration', 0);
|
||||
$client->getContainer()->get(Config::class)->set('api_user_registration', '0');
|
||||
}
|
||||
|
||||
public function testCreateNewUserWhenRegistrationIsDisabled()
|
||||
|
||||
@ -3,7 +3,6 @@
|
||||
namespace Tests\Wallabag\Controller\Api;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use FOS\UserBundle\Model\UserInterface;
|
||||
use FOS\UserBundle\Model\UserManager;
|
||||
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
@ -17,7 +16,7 @@ abstract class WallabagApiTestCase extends WebTestCase
|
||||
protected $client;
|
||||
|
||||
/**
|
||||
* @var UserInterface
|
||||
* @var User
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
@ -49,9 +48,12 @@ abstract class WallabagApiTestCase extends WebTestCase
|
||||
$userManager = $container->get('fos_user.user_manager');
|
||||
$firewallName = $container->getParameter('fos_user.firewall_name');
|
||||
|
||||
$this->user = $userManager->findUserBy(['username' => 'admin']);
|
||||
$adminUser = $userManager->findUserBy(['username' => 'admin']);
|
||||
\assert($adminUser instanceof User);
|
||||
|
||||
$client->loginUser($this->user, $firewallName);
|
||||
$this->user = $adminUser;
|
||||
|
||||
$client->loginUser($adminUser, $firewallName);
|
||||
|
||||
return $client;
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase
|
||||
$this->markTestSkipped('fosuser_registration is not enabled.');
|
||||
}
|
||||
|
||||
$client->getContainer()->get(Config::class)->set('api_user_registration', 1);
|
||||
$client->getContainer()->get(Config::class)->set('api_user_registration', '1');
|
||||
|
||||
$client->request('GET', '/api/info');
|
||||
|
||||
@ -53,7 +53,7 @@ class WallabagRestControllerTest extends WallabagApiTestCase
|
||||
|
||||
$this->assertTrue($content['allowed_registration']);
|
||||
|
||||
$client->getContainer()->get(Config::class)->set('api_user_registration', 0);
|
||||
$client->getContainer()->get(Config::class)->set('api_user_registration', '0');
|
||||
|
||||
$client->request('GET', '/api/info');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user