<commit_before><?php

namespace Acme\DemoBundle\Tests\Controller;

use Bazinga\Bundle\RestExtraBundle\Test\WebTestCase;
use FOS\RestBundle\Util\Codes;
use Symfony\Component\BrowserKit\Client;

class NoteControllerTest extends WebTestCase
{
    public function testGetNotes()
    {
        $client = $this->getClient(true);

        // head request
        $client->request('HEAD', '/notes.json');
        $response = $client->getResponse();

        $this->assertJsonResponse($response);
        $this->assertEquals(200, $response->getStatusCode(), $response->getContent());

        // empty list
        $client->request('GET', '/notes.json');
        $response = $client->getResponse();

        $this->assertJsonResponse($response);
        $this->assertEquals(200, $response->getStatusCode(), $response->getContent());
        $this->assertEquals('{"notes":[],"limit":5,"_links":{"self":{"href":"http:\/\/localhost\/notes"},"note":{"href":"http:\/\/localhost\/notes\/{id}","templated":true}}}', $response->getContent());

        // list
        $this->createNote($client, 'my note for list');

        $client->request('GET', '/notes.json');
        $response = $client->getResponse();

        $this->assertJsonResponse($response);
        $this->assertEquals(200, $response->getStatusCode(), $response->getContent());
        $contentWithoutSecret = preg_replace('/"secret":"[^"]*"/', '"secret":"XXX"', $response->getContent());
        $this->assertEquals('{"notes":[{"secret":"XXX","message":"my note for list","_links":{"self":{"href":"http:\/\/localhost\/notes\/0"}}}],"limit":5,"_links":{"self":{"href":"http:\/\/localhost\/notes"},"note":{"href":"http:\/\/localhost\/notes\/{id}","templated":true}}}', $contentWithoutSecret);
    }

    public function testGetNote()
    {
        $client = $this->getClient(true);

        $client->request('GET', '/notes/0.json');
        $response = $client->getResponse();

        $this->assertEquals(404, $response->getStatusCode(), $response->getContent());
        $this->assertEquals('{"code":404,"message":"Note does not exist."}', $response->getContent());

        $this->createNote($client, 'my note for get');

        $client->request('GET', '/notes/0.json');
        $response = $client->getResponse();

        $this->assertJsonResponse($response);
        $this->assertEquals(200, $response->getStatusCode(), $response->getContent());
        $contentWithoutSecret = preg_replace('/"secret":"[^"]*"/', '"secret":"XXX"', $response->getContent());
        $this->assertEquals('{"secret":"XXX","message":"my note for get","_links":{"self":{"href":"http:\/\/localhost\/notes\/0"}}}', $contentWithoutSecret);
    }

    public function testNewNote()
    {
        $client = $this->getClient(true);

        $client->request('GET', '/notes/new.json');
        $response = $client->getResponse();

        $this->assertJsonResponse($response);
        $this->assertEquals(200, $response->getStatusCode(), $response->getContent());
        $this->assertEquals('{"children":{"message":[]}}', $response->getContent());
    }

    public function testPostNote()
    {
        $client = $this->getClient(true);

        $this->createNote($client, 'my note for post');

        $response = $client->getResponse();

        $this->assertJsonResponse($response, Codes::HTTP_CREATED);
        $this->assertTrue($response->headers->contains('location', 'http://localhost/notes'));
    }

    public function testEditNote()
    {
        $client = $this->getClient(true);

        $client->request('GET', '/notes/0/edit.json');
        $response = $client->getResponse();

        $this->assertEquals(404, $response->getStatusCode(), $response->getContent());
        $this->assertEquals('{"code":404,"message":"Note does not exist."}', $response->getContent());

        $this->createNote($client, 'my note for post');

        $client->request('GET', '/notes/0/edit.json');
        $response = $client->getResponse();

        $this->assertJsonResponse($response);
        $this->assertEquals(200, $response->getStatusCode(), $response->getContent());
        $this->assertEquals('{"children":{"message":[]}}', $response->getContent());
    }

    public function testPutShouldModifyANote()
    {
        $client = $this->getClient(true);

        $client->request('PUT', '/notes/0.json', array(
            'note' => array(
                'message' => ''
            )
        ));
        $response = $client->getResponse();

        $this->assertEquals(400, $response->getStatusCode(), $response->getContent());
        $this->assertEquals('{"code":400,"message":"Validation Failed","errors":{"children":{"message":{"errors":["This value should not be blank."]}}}}', $response->getContent());

        $this->createNote($client, 'my note for post');

        $client->request('PUT', '/notes/0.json', array(
            'note' => array(
                'message' => 'my note for put'
            )
        ));
        $response = $client->getResponse();

        $this->assertJsonResponse($response, Codes::HTTP_NO_CONTENT);<commit_msg>fix tests<commit_after><?php

namespace Acme\DemoBundle\Tests\Controller;

use Bazinga\Bundle\RestExtraBundle\Test\WebTestCase;
use FOS\RestBundle\Util\Codes;
use Symfony\Component\BrowserKit\Client;

class NoteControllerTest extends WebTestCase
{
    public function testGetNotes()
    {
        $client = $this->getClient(true);

        // head request
        $client->request('HEAD', '/notes.json');
        $response = $client->getResponse();
        $this->assertEquals(200, $response->getStatusCode(), $response->getContent());

        // empty list
        $client->request('GET', '/notes.json');
        $response = $client->getResponse();

        $this->assertJsonResponse($response);
        $this->assertEquals('{"notes":[],"limit":5,"_links":{"self":{"href":"http:\/\/localhost\/notes"},"note":{"href":"http:\/\/localhost\/notes\/{id}","templated":true}}}', $response->getContent());

        // list
        $this->createNote($client, 'my note for list');

        $client->request('GET', '/notes.json');
        $response = $client->getResponse();

        $this->assertJsonResponse($response);
        $contentWithoutSecret = preg_replace('/"secret":"[^"]*"/', '"secret":"XXX"', $response->getContent());
        $this->assertEquals('{"notes":[{"secret":"XXX","message":"my note for list","_links":{"self":{"href":"http:\/\/localhost\/notes\/0"}}}],"limit":5,"_links":{"self":{"href":"http:\/\/localhost\/notes"},"note":{"href":"http:\/\/localhost\/notes\/{id}","templated":true}}}', $contentWithoutSecret);
    }

    public function testGetNote()
    {
        $client = $this->getClient(true);

        $client->request('GET', '/notes/0.json');
        $response = $client->getResponse();

        $this->assertEquals(404, $response->getStatusCode(), $response->getContent());
        $this->assertEquals('{"code":404,"message":"Note does not exist."}', $response->getContent());

        $this->createNote($client, 'my note for get');

        $client->request('GET', '/notes/0.json');
        $response = $client->getResponse();

        $this->assertJsonResponse($response);
        $contentWithoutSecret = preg_replace('/"secret":"[^"]*"/', '"secret":"XXX"', $response->getContent());
        $this->assertEquals('{"secret":"XXX","message":"my note for get","_links":{"self":{"href":"http:\/\/localhost\/notes\/0"}}}', $contentWithoutSecret);
    }

    public function testNewNote()
    {
        $client = $this->getClient(true);

        $client->request('GET', '/notes/new.json');
        $response = $client->getResponse();

        $this->assertJsonResponse($response);
        $this->assertEquals('{"children":{"message":[]}}', $response->getContent());
    }

    public function testPostNote()
    {
        $client = $this->getClient(true);

        $this->createNote($client, 'my note for post');

        $response = $client->getResponse();

        $this->assertJsonResponse($response, Codes::HTTP_CREATED);
        $this->assertTrue($response->headers->contains('location', 'http://localhost/notes'));
    }

    public function testEditNote()
    {
        $client = $this->getClient(true);

        $client->request('GET', '/notes/0/edit.json');
        $response = $client->getResponse();

        $this->assertEquals(404, $response->getStatusCode(), $response->getContent());
        $this->assertEquals('{"code":404,"message":"Note does not exist."}', $response->getContent());

        $this->createNote($client, 'my note for post');

        $client->request('GET', '/notes/0/edit.json');
        $response = $client->getResponse();

        $this->assertJsonResponse($response);
        $this->assertEquals('{"children":{"message":[]}}', $response->getContent());
    }

    public function testPutShouldModifyANote()
    {
        $client = $this->getClient(true);

        $client->request('PUT', '/notes/0.json', array(
            'note' => array(
                'message' => ''
            )
        ));
        $response = $client->getResponse();

        $this->assertEquals(400, $response->getStatusCode(), $response->getContent());
        $this->assertEquals('{"code":400,"message":"Validation Failed","errors":{"children":{"message":{"errors":["This value should not be blank."]}}}}', $response->getContent());

        $this->createNote($client, 'my note for post');

        $client->request('PUT', '/notes/0.json', array(
            'note' => array(
                'message' => 'my note for put'
            )
        ));
        $response = $client->getResponse();

        $this->assertJsonResponse($response, Codes::HTTP_NO_CONTENT);
{'fraction_non_alphanumeric': 0.217485549132948, 'fraction_numerical': 0.007947976878612716, 'mean_word_length': 3.398093508851566, 'pattern_counts': {'":': 88, '<': 5, '<?xml version=': 0, '>': 167, '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': '826036', 'n_tokens_mistral': 2785, 'n_tokens_neox': 2648, 'n_words': 400}