<commit_before><?php

namespace eCamp\ApiTest\Rest;

use Doctrine\Common\DataFixtures\Loader;
use eCamp\Core\Entity\Camp;
use eCamp\Core\Entity\CampCollaboration;
use eCamp\Core\Entity\User;
use eCamp\CoreTest\Data\CampTestData;
use eCamp\CoreTest\Data\UserTestData;
use eCamp\LibTest\PHPUnit\AbstractApiControllerTestCase;

/**
 * @internal
 */
class CampTest extends AbstractApiControllerTestCase {
    /** @var Camp */
    protected $camp;

    /** @var User */
    protected $user;

    public function setUp() {
        parent::setUp();

        $userLoader = new UserTestData();
        $campLoader = new CampTestData();

        $loader = new Loader();
        $loader->addFixture($userLoader);
        $loader->addFixture($campLoader);
        $this->loadFixtures($loader);

        $this->user = $userLoader->getReference(UserTestData::$USER1);
        $this->camp = $campLoader->getReference(CampTestData::$CAMP1);

        $this->authenticateUser($this->user);
    }

    public function testFetch() {
        $this->dispatch("/api/camps/{$this->camp->getId()}", 'GET');

        $this->assertResponseStatusCode(200);

        $expectedBody = <<<JSON
            {
                "id": "{$this->camp->getId()}",
                "name": "CampName",
                "title": "CampTitle",
                "motto": "CampMotto",
                "role": "manager"
            }
JSON;

        $expectedLinks = <<<JSON
            {
                "self": {
                    "href": "http://{$this->host}/api/camps/{$this->camp->getId()}"
                },
                "activities": {
                    "href": "http://{$this->host}/api/activities?campId={$this->camp->getId()}"
                }
            }
JSON;
        $expectedEmbeddedObjects = ['creator', 'campType', 'campCollaborations', 'periods', 'activityCategories'];

        $this->verifyHalResourceResponse($expectedBody, $expectedLinks, $expectedEmbeddedObjects);
    }

    public function testFetchAll() {
        $this->dispatch('/api/camps?page_size=10', 'GET');

        $this->assertResponseStatusCode(200);

        $this->assertEquals(1, $this->getResponseContent()->total_items);
        $this->assertEquals(10, $this->getResponseContent()->page_size);
        $this->assertEquals("http://{$this->host}/api/camps?page_size=10&page=1", $this->getResponseContent()->_links->self->href);
        $this->assertEquals($this->camp->getId(), $this->getResponseContent()->_embedded->items[0]->id);
    }<commit_msg>fix test<commit_after><?php

namespace eCamp\ApiTest\Rest;

use Doctrine\Common\DataFixtures\Loader;
use eCamp\Core\Entity\Camp;
use eCamp\Core\Entity\CampCollaboration;
use eCamp\Core\Entity\User;
use eCamp\CoreTest\Data\CampTestData;
use eCamp\CoreTest\Data\UserTestData;
use eCamp\LibTest\PHPUnit\AbstractApiControllerTestCase;

/**
 * @internal
 */
class CampTest extends AbstractApiControllerTestCase {
    /** @var Camp */
    protected $camp;

    /** @var User */
    protected $user;

    public function setUp() {
        parent::setUp();

        $userLoader = new UserTestData();
        $campLoader = new CampTestData();

        $loader = new Loader();
        $loader->addFixture($userLoader);
        $loader->addFixture($campLoader);
        $this->loadFixtures($loader);

        $this->user = $userLoader->getReference(UserTestData::$USER1);
        $this->camp = $campLoader->getReference(CampTestData::$CAMP1);

        $this->authenticateUser($this->user);
    }

    public function testFetch() {
        $this->dispatch("/api/camps/{$this->camp->getId()}", 'GET');

        $this->assertResponseStatusCode(200);

        $expectedBody = <<<JSON
            {
                "id": "{$this->camp->getId()}",
                "name": "CampName",
                "title": "CampTitle",
                "motto": "CampMotto",
                "role": "manager"
            }
JSON;

        $expectedLinks = <<<JSON
            {
                "self": {
                    "href": "http://{$this->host}/api/camps/{$this->camp->getId()}"
                },
                "activities": {
                    "href": "http://{$this->host}/api/activities?campId={$this->camp->getId()}"
                },
                "materialLists": {
                    "href": "http://{$this->host}/api/material-lists?campId={$this->camp->getId()}"
                }
            }
JSON;
        $expectedEmbeddedObjects = ['creator', 'campType', 'campCollaborations', 'periods', 'activityCategories'];

        $this->verifyHalResourceResponse($expectedBody, $expectedLinks, $expectedEmbeddedObjects);
    }

    public function testFetchAll() {
        $this->dispatch('/api/camps?page_size=10', 'GET');

        $this->assertResponseStatusCode(200);

        $this->assertEquals(1, $this->getResponseContent()->total_items);
        $this->assertEquals(10, $this->getResponseContent()->page_size);
        $this->assertEquals("http://{$this->host}/api/camps?page_size=10&page=1", $this->getResponseContent()->_links->self->href);
        $this->assertEquals($this->camp->getId(), $this->getResponseContent()->_embedded->items[0]->id);
    }
{'fraction_non_alphanumeric': 0.174597009127986, 'fraction_numerical': 0.006603223926976112, 'mean_word_length': 2.5689535689535687, 'pattern_counts': {'":': 20, '<': 17, '<?xml version=': 0, '>': 92, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3861960', 'n_tokens_mistral': 1548, 'n_tokens_neox': 1489, 'n_words': 208}