<commit_before><?php

namespace TreeHouse\SwiftBundle\Tests\Functional\Controller;

use Symfony\Component\HttpFoundation\Response;

class ObjectControllerTest extends AbstractControllerTest
{
    protected $containerName = 'test';
    protected $objectName1   = 'foo';
    protected $objectName2   = 'bar';
    protected $objectName3   = 'foobar';

    protected $path1;
    protected $path2;
    protected $path3;

    protected $file;
    protected $fileContents;
    protected $fileSize;
    protected $fileHash;

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

        $this->deleteContainer();

        $this->path1 = sprintf('%s/%s', $this->containerName, $this->objectName1);
        $this->path2 = sprintf('%s/%s', $this->containerName, $this->objectName2);
        $this->path3 = sprintf('%s/%s', $this->containerName, $this->objectName3);

        $this->fileContents = 'foobar';
        $this->file = static::$kernel->getContainer()->getParameter('kernel.cache_dir').'/swift_object';

        file_put_contents($this->file, $this->fileContents);

        $this->fileHash = md5_file($this->file);
        $this->fileSize = filesize($this->file);
    }

    public function testAuth()
    {
        $client = static::createClient();

        foreach (['HEAD', 'GET', 'PUT', 'POST', 'COPY', 'DELETE'] as $method) {
            $client->request($method, $this->getObjectRoute());
            $this->assertEquals(Response::HTTP_FORBIDDEN, $client->getResponse()->getStatusCode());
        }
    }

    public function testObjectNotFound()
    {
        foreach (['HEAD', 'GET', 'POST', 'COPY', 'DELETE'] as $method) {
            $this->assertEquals(Response::HTTP_NOT_FOUND, $this->request($method, $this->getObjectRoute())->getStatusCode());
        }
    }

    public function testPutObject()
    {
        $this->createContainer();

        $response = $this->request('PUT', $this->getObjectRoute(), [], [], ['HTTP_Content-Type' => 'text/plain', 'HTTP_Content-Length' => $this->fileSize], $this->fileContents);
        $this->assertEquals(Response::HTTP_CREATED, $response->getStatusCode(), $response->getContent());
    }

    public function testPutObjectNoContentLengthOrContentType()
    {
        $this->markTestIncomplete('Kernel automatically adds content length/type headers. Find a way to bypass this');

        $this->createContainer();

        $response = $this->request('PUT', $this->getObjectRoute(), [], [], ['HTTP_Content-Length' => $this->fileSize]);
        $this->assertEquals(Response::HTTP_LENGTH_REQUIRED, $response->getStatusCode());

        $response = $this->request('PUT', $this->getObjectRoute(), [], [], ['HTTP_Content-Type' => 'text/plain']);
        $this->assertEquals(Response::HTTP_LENGTH_REQUIRED, $response->getStatusCode());
    }

    public function testPutObjectWithIntegrity()<commit_msg>See if Scrutinizer works when this is commentedwq<commit_after><?php

namespace TreeHouse\SwiftBundle\Tests\Functional\Controller;

use Symfony\Component\HttpFoundation\Response;

class ObjectControllerTest extends AbstractControllerTest
{
    protected $containerName = 'test';
    protected $objectName1   = 'foo';
    protected $objectName2   = 'bar';
    protected $objectName3   = 'foobar';

    protected $path1;
    protected $path2;
    protected $path3;

    protected $file;
    protected $fileContents;
    protected $fileSize;
    protected $fileHash;

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

        $this->deleteContainer();

        $this->path1 = sprintf('%s/%s', $this->containerName, $this->objectName1);
        $this->path2 = sprintf('%s/%s', $this->containerName, $this->objectName2);
        $this->path3 = sprintf('%s/%s', $this->containerName, $this->objectName3);

        $this->fileContents = 'foobar';
        $this->file = static::$kernel->getContainer()->getParameter('kernel.cache_dir').'/swift_object';

        file_put_contents($this->file, $this->fileContents);

        $this->fileHash = md5_file($this->file);
        $this->fileSize = filesize($this->file);
    }

    public function testAuth()
    {
        $client = static::createClient();

        foreach (['HEAD', 'GET', 'PUT', 'POST', 'COPY', 'DELETE'] as $method) {
            $client->request($method, $this->getObjectRoute());
            $this->assertEquals(Response::HTTP_FORBIDDEN, $client->getResponse()->getStatusCode());
        }
    }

    public function testObjectNotFound()
    {
        foreach (['HEAD', 'GET', 'POST', 'COPY', 'DELETE'] as $method) {
            $this->assertEquals(Response::HTTP_NOT_FOUND, $this->request($method, $this->getObjectRoute())->getStatusCode());
        }
    }

    public function testPutObject()
    {
        $this->createContainer();

        $response = $this->request('PUT', $this->getObjectRoute(), [], [], ['HTTP_Content-Type' => 'text/plain', 'HTTP_Content-Length' => $this->fileSize], $this->fileContents);
        $this->assertEquals(Response::HTTP_CREATED, $response->getStatusCode(), $response->getContent());
    }

//    public function testPutObjectNoContentLengthOrContentType()
//    {
//        $this->markTestIncomplete('Kernel automatically adds content length/type headers. Find a way to bypass this');
//
//        $this->createContainer();
//
//        $response = $this->request('PUT', $this->getObjectRoute(), [], [], ['HTTP_Content-Length' => $this->fileSize]);
//        $this->assertEquals(Response::HTTP_LENGTH_REQUIRED, $response->getStatusCode());
//
//        $response = $this->request('PUT', $this->getObjectRoute(), [], [], ['HTTP_Content-Type' => 'text/plain']);
//        $this->assertEquals(Response::HTTP_LENGTH_REQUIRED, $response->getStatusCode());
//    }

    public function testPutObjectWithIntegrity()
{'fraction_non_alphanumeric': 0.17463617463617465, 'fraction_numerical': 0.0045045045045045045, 'mean_word_length': 3.5890302066772657, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 107, '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': '5015122', 'n_tokens_mistral': 1673, 'n_tokens_neox': 1644, 'n_words': 290}