Commit 18094943 authored by Адлан Шамавов's avatar Адлан Шамавов
Browse files

STA-968 | Добавил тесты для контроллеров

parent 819d40f2
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@ APP_SECRET=ea3ebbf899855d483050e0d1aad6a759
# DATABASE_URL="sqlite:///%kernel.project_dir%/var/data.db"
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=8.0.32&charset=utf8mb4"
# DATABASE_URL="mysql://app:!ChangeMe!@127.0.0.1:3306/app?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
DATABASE_URL="postgresql://postgres:12345@postgres/postgres?serverVersion=16&charset=utf8"
DATABASE_URL="postgresql://postgres:12345@postgres/postgres_test?serverVersion=16&charset=utf8"
###< doctrine/doctrine-bundle ###

###> symfony/messenger ###
+0 −0

Empty file deleted.

+1 −5
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ use Doctrine\Migrations\AbstractMigration;
/**
 * Auto-generated Migration: Please modify to your needs!
 */
final class Version20240502094853 extends AbstractMigration
final class Version20240503065723 extends AbstractMigration
{
    public function getDescription(): string
    {
@@ -20,8 +20,6 @@ final class Version20240502094853 extends AbstractMigration
    public function up(Schema $schema): void
    {
        // this up() migration is auto-generated, please modify it to your needs
        $this->addSql('DROP SEQUENCE gallery_id_seq CASCADE');
        $this->addSql('DROP SEQUENCE seo_id_seq CASCADE');
        $this->addSql('CREATE TABLE file (id UUID NOT NULL, name VARCHAR(255) NOT NULL, description VARCHAR(255) NOT NULL, size INT NOT NULL, type VARCHAR(255) NOT NULL, url VARCHAR(255) NOT NULL, PRIMARY KEY(id))');
        $this->addSql('COMMENT ON COLUMN file.id IS \'(DC2Type:uuid)\'');
        $this->addSql('CREATE TABLE gallery (id UUID NOT NULL, restaurant_id UUID NOT NULL, file_id UUID NOT NULL, PRIMARY KEY(id))');
@@ -129,8 +127,6 @@ final class Version20240502094853 extends AbstractMigration
    {
        // this down() migration is auto-generated, please modify it to your needs
        $this->addSql('CREATE SCHEMA public');
        $this->addSql('CREATE SEQUENCE gallery_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
        $this->addSql('CREATE SEQUENCE seo_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
        $this->addSql('ALTER TABLE gallery DROP CONSTRAINT FK_472B783AB1E7706E');
        $this->addSql('ALTER TABLE gallery DROP CONSTRAINT FK_472B783A93CB796C');
        $this->addSql('ALTER TABLE kitchen DROP CONSTRAINT FK_EAA3CE34B1E7706E');
+148 −0
Original line number Diff line number Diff line
<?php

namespace App\Tests;

use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class NewsControllerTest extends WebTestCase
{
    private const NEWS_ID = '018f3d5b-65c7-7998-a6d5-2270db52f830';
    private const NEWS_CATEGORY_ID = '018f3d5b-65c7-7998-a6d5-2270da54ce3c';

    public function testNewsSuccessResponse(): void
    {
        $client = static::createClient();
        $crawler = $client->request(
            'GET',
            '/api/v1/news?page=1&limit=12'
        );

        $this->assertResponseIsSuccessful();
    }

    public function testNewsJsonDataPartly(): void
    {
        $client = static::createClient();
        $crawler = $client->request(
            'GET',
            '/api/v1/news'
        );
        $data = $client->getResponse()->getContent();

        $this->assertStringContainsString('url' , $data);
    }

    public function testNewsJsonData(): void
    {
        $client = static::createClient();
        $crawler = $client->request(
            'GET',
            '/api/v1/news?page=1&limit=12'
        );
        $data = $client->getResponse()->getContent();
        $expected = file_get_contents(__DIR__ . '/responses/news.json');

        $this->assertJsonStringEqualsJsonString($expected, $data);
    }

    public function testNewsWithNewsCategory(): void
    {
        $client = static::createClient();
        $crawler = $client->request(
            'GET',
            '/api/v1/news?page=1&limit=12&news_category_id=' . self::NEWS_CATEGORY_ID
        );
        $data = $client->getResponse()->getContent();
        $expected = file_get_contents(__DIR__ . '/responses/news.json');

        $this->assertJsonStringEqualsJsonString($expected, $data);
    }

    public function testMainNewsJsonDataPartly(): void
    {
        $client = static::createClient();
        $crawler = $client->request(
            'GET',
            '/api/v1/news/mainNews'
        );
        $data = $client->getResponse()->getContent();

        $this->assertStringContainsString('name' , $data);
    }

    public function testMainNews(): void
    {
        $client = static::createClient();
        $crawler = $client->request(
            'GET',
            '/api/v1/news/mainNews'
        );
        $data = $client->getResponse()->getContent();
        $expected = file_get_contents(__DIR__ . '/responses/mainNews.json');

        $this->assertJsonStringEqualsJsonString($expected, $data);
    }

    public function testSearchNewsJsonDataPartly(): void
    {
        $client = static::createClient();
        $crawler = $client->request(
            'GET',
            '/api/v1/news/search'
        );
        $data = $client->getResponse()->getContent();

        $this->assertStringContainsString('seoTitle' , $data);
    }

    public function testSearchNews(): void
    {
        $client = static::createClient();
        $crawler = $client->request(
            'GET',
            '/api/v1/news/search'
        );
        $data = $client->getResponse()->getContent();
        $expected = file_get_contents(__DIR__ . '/responses/searchNews.json');

        $this->assertJsonStringEqualsJsonString($expected, $data);
    }

    public function testNewsOne(): void
    {
        $client = static::createClient();
        $crawler = $client->request(
            'GET',
            '/api/v1/news/' . self::NEWS_ID
        );
        $data = $client->getResponse()->getContent();
        $expected = file_get_contents(__DIR__ . '/responses/searchNews.json');

        $this->assertJsonStringEqualsJsonString($expected, $data);
    }

    public function testNewsOneJsonDataPartly(): void
    {
        $client = static::createClient();
        $crawler = $client->request(
            'GET',
            '/api/v1/news/' . self::NEWS_ID
        );
        $data = $client->getResponse()->getContent();

        $this->assertStringContainsString('createAt' , $data);
    }

    public function testNewsOneNotFound(): void
    {
        $client = static::createClient();
        $crawler = $client->request(
            'GET',
            '/api/v1/news/test'
        );
        $data = $client->getResponse()->getContent();
        $expected = file_get_contents(__DIR__ . '/responses/newsNotFound.json');

        $this->assertJsonStringEqualsJsonString($expected, $data);
    }
}
 No newline at end of file
+112 −51
Original line number Diff line number Diff line
@@ -8,56 +8,117 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;

class RestaurantControllerTest extends WebTestCase
{
    public function testRestaurants(): void
    {
        $client = static::createClient();
        $content = $client->request('GET', '/api/v1/restaurants?page=1&limit=12');
        $actual = json_decode($client->getResponse()->getContent(), true, 512, JSON_THROW_ON_ERROR);
        $expect = '{
    "pagination": {
        "currentPage": 1,
        "pages": 1,
        "pageSize": 12
    },
    "list": [
        {
            "id": 1,
            "name": "Ресторан «Арктика»",
            "code": "restoran-arktika",
            "type": {
                "id": 1,
                "name": "Ресторан",
                "code": "restoran"
            },
            "check": "bla bla",
            "image": {
                "id": 1,
                "name": "name",
                "description": "description",
                "size": 10,
                "type": "jpg",
                "url": "/upload/preview.png"
            },
            "detailLink": "https://visityamal.ru/"
        }
    ],
    "filterVariants": {
        "type": [
            {
                "id": 1,
                "name": "Ресторан",
                "code": "restoran"
            }
        ],
        "kitchen": [
            {
                "id": 1,
                "name": "Азиатская"
            }
        ]
    }
}';
        self::assertResponseIsSuccessful();
        self::assertJsonStringEqualsJsonString($expect, $actual);
    private const RESTAURANT_ID = '018f3d5b-6688-7a34-b4ee-415cc851d5fa';
    private const RESTAURANT_TYPE_ID = '018f3d5b-6688-7a34-b4ee-415cc59ae55a';

    public function testRestaurantsSuccessResponse(): void
    {
        $client = static::createClient();
        $crawler = $client->request(
            'GET',
            '/api/v1/restaurants?page=1&limit=12'
        );

        $this->assertResponseIsSuccessful();
    }

    public function testRestaurantsSuccessResponseWithoutQuery(): void
    {
        $client = static::createClient();
        $crawler = $client->request(
            'GET',
            '/api/v1/restaurants'
        );

        $this->assertResponseIsSuccessful();
    }

    public function testRestaurantsJsonDataPartly(): void
    {
        $client = static::createClient();
        $crawler = $client->request(
            'GET',
            '/api/v1/restaurants'
        );
        $data = $client->getResponse()->getContent();

        $this->assertStringContainsString('image' , $data);
    }

    public function testRestaurantsJsonData(): void
    {
        $client = static::createClient();
        $crawler = $client->request(
            'GET',
            '/api/v1/restaurants?page=1&limit=12'
        );
        $data = $client->getResponse()->getContent();
        $expected = file_get_contents(__DIR__ . '/responses/restaurants.json');

        $this->assertJsonStringEqualsJsonString($expected, $data);
    }

    public function testRestaurantsWithTypeId(): void
    {
        $client = static::createClient();
        $crawler = $client->request(
            'GET',
            '/api/v1/restaurants?page=1&limit=12&restaurant_type_id='
            . self::RESTAURANT_TYPE_ID
        );
        $data = $client->getResponse()->getContent();
        $expected = file_get_contents(__DIR__ . '/responses/restaurants.json');

        $this->assertJsonStringEqualsJsonString($expected, $data);
    }

    public function testRestaurantSuccessResponse(): void
    {
        $client = static::createClient();
        $crawler = $client->request(
            'GET',
            '/api/v1/restaurants/' . self::RESTAURANT_ID
        );

        $this->assertResponseIsSuccessful();
    }

    public function testRestaurantJsonDataPartly(): void
    {
        $client = static::createClient();
        $crawler = $client->request(
            'GET',
            '/api/v1/restaurants/' . self::RESTAURANT_ID
        );
        $data = $client->getResponse()->getContent();

        $this->assertStringContainsString('tags' , $data);
    }

    public function testRestaurantJsonData(): void
    {
        $client = static::createClient();
        $crawler = $client->request(
            'GET',
            '/api/v1/restaurants/' . self::RESTAURANT_ID
        );
        $data = $client->getResponse()->getContent();
        $expected = file_get_contents(__DIR__ . '/responses/restaurant.json');

        $this->assertJsonStringEqualsJsonString($expected, $data);
    }

    public function testRestaurantNotFound(): void
    {
        $client = static::createClient();
        $crawler = $client->request(
            'GET',
            '/api/v1/restaurants/test'
        );

        $data = $client->getResponse()->getContent();
        $expected = file_get_contents(__DIR__ . '/responses/restaurantNotFound.json');

        $this->assertJsonStringEqualsJsonString($expected, $data);
    }
}
Loading