Я пытаюсь проверить метод регистрации, однако я получаю это в журналах.
[2018-08-30 00:13:50] request.INFO: Соответствующий маршрут "регистрация".
{ "Маршрут": "Регистрация", "route_parameters": { "_ маршрут": "Регистрация", "_ контроллер": "App \ Controller \ UserController :: Регистрация"}, "REQUEST_URI": "http://localhost/signup","method":"POST"}
[] [2018-08-30 00:13:50] security.INFO: Заполнено хранилище TokenStorage
с анонимным токеном. [] [] [2018-08-30 00:13:50] доктрина. ОТЛАДКА:
«НАЧАЛО СДЕЛКИ» [] [] [2018-08-30 00:13:50] доктрина. ОТЛАДКА:
"ROLLBACK" [] [] [2018-08-30 00:13:50] request.CRITICAL: необученный PHP
Доктрина исключений \ DBAL \ Exception \ TableNotFoundException: "An
возникла исключительная ситуация при выполнении 'INSERT INTO user (электронная почта, имя пользователя,
is_active, пароль, роли) VALUES (?,?,?,?,?) ': SQLSTATE [HY000]:
Общая ошибка: 1 нет такой таблицы: пользователь "в
/Applications/MAMP/htdocs/my_project/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractSQLiteDriver.php
строка 63 {"исключение": "[объект]
(Doctrine \ DBAL \ Exception \ TableNotFoundException (код: 0): An
возникла исключительная ситуация при выполнении 'INSERT INTO user (электронная почта, имя пользователя,
is_active, пароль, роли) ЗНАЧЕНИЯ (?,?,?,?,
?) ': \ n \ nSQLSTATE [HY000]: общая ошибка: 1 нет такой таблицы: пользователь в
/Applications/MAMP/htdocs/my_project/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractSQLiteDriver.php:63,
Doctrine \ DBAL \ Driver \ PDOException (код: HY000): SQLSTATE [HY000]:
Общая ошибка: 1 нет такой таблицы: пользователь на
/Applications/MAMP/htdocs/my_project/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:82,
PDOException (код: HY000): SQLSTATE [HY000]: общая ошибка: 1 нет такого
таблица: пользователь на
/Applications/MAMP/htdocs/my_project/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:80) "}
[]
и это как ошибка
Failed asserting that 500 is identical to 200.
SignUpControllerTest.php
<?php
namespace App\Tests\Controller;
use App\Entity\Product;
use App\Entity\Category;
use App\Entity\User;
use App\Repository\UserRepository;
use App\Repository\CategoryRepository;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\DBAL\Schema\SchemaException;
use Doctrine\ORM\Tools\SchemaTool;
class SignUpControllerTest extends WebTestCase
{
/**
* @var \Doctrine\ORM\EntityManager
*/
private $em;
/**
* {@inheritDoc}
*/
protected function setUp()
{
self::bootKernel();
$this->em = static::$kernel->getContainer()
->get('doctrine')
->getManager();
parent::setUp();
}
public function testUserCreate()
{
$client = static::createClient();
$client->request('POST', '/signup', [], [], [], json_encode([
'user' => [
'username' => 'chuck_norris',
'password' => 'foobar',
'email' => 'chuck@norris.com',
'roles' => 'ROLE_USER'
],
]));
$response = $client->getResponse();
$this->assertSame(Response::HTTP_OK, $response->getStatusCode());
$data = json_decode($response->getContent(), true);
$this->assertArrayHasKey('user', $data);
$this->assertSame('chuck@norris.com', $data['user']['email']);
$this->assertSame('chuck_norris', $data['user']['username']);
}
UserController.php
/**
* @Route("/signup", name="signup")
*/
public function signup(Request $request, UserPasswordEncoderInterface $passwordEncoder )
{
$user = new User();
$entityManager = $this->getDoctrine()->getManager();
$user->setEmail($request->get('email'));
$user->setPlainPassword($request->get('password'));
$user->setUsername($request->get('username'));
$password = $passwordEncoder->encodePassword($user, $user->getPlainPassword());
$user->setPassword($password);
$entityManager->persist($user);
$entityManager->flush();
return $this->redirectToRoute('login');
}
User.php (сущность)
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* @ORM\Entity
* @UniqueEntity(fields="email", message="Email already taken")
* @UniqueEntity(fields="username", message="Username already taken")
*/
class User implements UserInterface, \Serializable
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(type="string", length=190, unique=true)
* @Assert\NotBlank()
* @Assert\Email()
*/
private $email;
/**
* @ORM\Column(type="string", length=190, unique=true)
* @Assert\NotBlank()
*/
private $username;
/**
* @ORM\Column(name="is_active", type="boolean")
*/
private $isActive;
/**
* @Assert\NotBlank()
* @Assert\Length(max=190)
*/
private $plainPassword;
/**
* The below length depends on the "algorithm" you use for encoding
* the password, but this works well with bcrypt.
*
* @ORM\Column(type="string", length=64)
*/
private $password;
/**
* @ORM\Column(type="array")
*/
private $roles;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Product", mappedBy="user")
*/
private $products;
public function __construct()
{
$this->roles = array('ROLE_USER');
$this->isActive = true;
$this->products = new ArrayCollection();
}
// other properties and methods
public function getEmail()
{
return $this->email;
}
public function isEnabled()
{
return $this->isActive;
}
public function setEmail($email)
{
$this->email = $email;
}
public function getUsername()
{
return $this->username;
}
public function setUsername($username)
{
$this->username = $username;
}
public function getPlainPassword()
{
return $this->plainPassword;
}
public function setPlainPassword($password)
{
$this->plainPassword = $password;
}
public function getPassword()
{
return $this->password;
}
public function setPassword($password)
{
$this->password = $password;
}
public function getSalt()
{
// The bcrypt and argon2i algorithms don't require a separate salt.
// You *may* need a real salt if you choose a different encoder.
return null;
}
public function getRoles()
{
return $this->roles;
}
public function eraseCredentials()
{
}
/** @see \Serializable::serialize() */
public function serialize()
{
return serialize(array(
$this->id,
$this->username,
$this->password,
// see section on salt below
// $this->salt,
));
}
/** @see \Serializable::unserialize() */
public function unserialize($serialized)
{
list (
$this->id,
$this->username,
$this->password,
// see section on salt below
// $this->salt
) = unserialize($serialized, array('allowed_classes' => false));
}
/**
* @return Collection|Product[]
*/
public function getProducts(): Collection
{
return $this->products;
}
public function addProduct(Product $product): self
{
if (!$this->products->contains($product)) {
$this->products[] = $product;
$product->setUser($this);
}
return $this;
}
public function removeProduct(Product $product): self
{
if ($this->products->contains($product)) {
$this->products->removeElement($product);
// set the owning side to null (unless already changed)
if ($product->getUser() === $this) {
$product->setUser(null);
}
}
return $this;
}
}