<commit_before><?php

namespace Todo;
use Aura\Sql\ExtendedPdo;
use Zend\Diactoros\ServerRequestFactory;

class AddItemTest extends AbstractTest
{
    protected function setUpRoute() 
    {       
        /*
        $this->adr->put('Todo\AddItem\Put', '/todo/add/{description}', 'Todo\Action\AddItem') 
            ->input('Todo\Input\AddItemInput')
            ->responder('Todo\Responder\AddItemResponder');
        */
       
        $this->adr->get('Todo\AddItem\Post', '/todo/add/{description}', 'Todo\Action\AddItem') 
            ->input('Todo\Input\AddItemInput')
            ->responder('Todo\Responder\AddItemResponder');
    }

    public function testAddingSuccess() 
    {           
        $todo = $this->mostRecentTodo();                
         $databaseHandle = \defaultTodoPdo();
        $apdo = new ExtendedPdo($databaseHandle);
        $affected = $apdo->perform(
            'INSERT INTO todo (
                userId,
                description
            ) VALUES (
                :userId,
                :description
            )',
            ['userId' => 523100, 'description' => 'zzzzzzzz'] 
        );
        if ($affected) 
            $id = $apdo->lastInsertId();
        var_dump($id);


        $todo = $this->mostRecentTodo();                
       
        /*
        $description = rand(0, 100000000) . ' :-)';
        $request = $this->newRequest('/todo/add/'.$description); // , 'GET'
        $response = $this->responseFromRun();
        */
        // $this->assertRelayResponse($response, 201, ['Content-Type' => ['application/json']], '{"description":"'.$description.'"}'); 
    }      

    /*
    public function testAddingSecond() 
    {        
        $description = rand(0, 100000000) . ' :-)';
        $request = $this->newRequest('/todo/add/'.$description); 
        $response = $this->responseFromRun();
        $this->assertRelayResponse($response, 201, ['Content-Type' => ['application/json']], '{"description":"'.$description.'"}');
        $todo = $this->mostRecentTodo(); 
    }


    /**
     * @TODO: BecauseItAlreadyExists && BecauseInvalid /// 500, 405
     * /
    public function testAddingFailure() 
    {          
        // getting most recent so we are trying to insert something that already exists
        $todo = $this->mostRecentTodo(); 
        $description = $todo['description'];
        $request = $this->newRequest('/todo/add/'.$description);

        $response = $this->responseFromRun();
        
        $this->assertRelayResponse($response, 400, ['Content-Type' => ['application/json']], '["a Todo with the same Description was found",{"description":"'.$description.'"}]');
    }  
    */  
}<commit_msg>PDO + ExtendedPDO<commit_after><?php

namespace Todo;
use Aura\Sql\ExtendedPdo;
use Zend\Diactoros\ServerRequestFactory;

class AddItemTest extends AbstractTest
{
    protected function setUpRoute() 
    {       
        /*
        $this->adr->put('Todo\AddItem\Put', '/todo/add/{description}', 'Todo\Action\AddItem') 
            ->input('Todo\Input\AddItemInput')
            ->responder('Todo\Responder\AddItemResponder');
        */
       
        $this->adr->get('Todo\AddItem\Post', '/todo/add/{description}', 'Todo\Action\AddItem') 
            ->input('Todo\Input\AddItemInput')
            ->responder('Todo\Responder\AddItemResponder');
    }

    public function testAddingSuccess() 
    {           
        $todo = $this->mostRecentTodo();                
         $databaseHandle = \defaultTodoPdo();
        $apdo = new ExtendedPdo($databaseHandle);
        $affected = $apdo->perform(
            'INSERT INTO todo (
                userId,
                description
            ) VALUES (
                :userId,
                :description
            )',
            ['userId' => 523100, 'description' => 'zzzzzzzz'] 
        );
        if ($affected) 
            $id = $apdo->lastInsertId();
        var_dump($id);
        
        $statementHandle = $databaseHandle->prepare("INSERT INTO todo (userId, description ) VALUES (144, 'eh')");
        $statementHandle->execute();

        $todo = $this->mostRecentTodo();                
       
        /*
        $description = rand(0, 100000000) . ' :-)';
        $request = $this->newRequest('/todo/add/'.$description); // , 'GET'
        $response = $this->responseFromRun();
        */
        // $this->assertRelayResponse($response, 201, ['Content-Type' => ['application/json']], '{"description":"'.$description.'"}'); 
    }      

    /*
    public function testAddingSecond() 
    {        
        $description = rand(0, 100000000) . ' :-)';
        $request = $this->newRequest('/todo/add/'.$description); 
        $response = $this->responseFromRun();
        $this->assertRelayResponse($response, 201, ['Content-Type' => ['application/json']], '{"description":"'.$description.'"}');
        $todo = $this->mostRecentTodo(); 
    }


    /**
     * @TODO: BecauseItAlreadyExists && BecauseInvalid /// 500, 405
     * /
    public function testAddingFailure() 
    {          
        // getting most recent so we are trying to insert something that already exists
        $todo = $this->mostRecentTodo(); 
        $description = $todo['description'];
        $request = $this->newRequest('/todo/add/'.$description);

        $response = $this->responseFromRun();
        
        $this->assertRelayResponse($response, 400, ['Content-Type' => ['application/json']], '["a Todo with the same Description was found",{"description":"'.$description.'"}]');
    }  
    */  
}
{'fraction_non_alphanumeric': 0.16750811395600432, 'fraction_numerical': 0.015326361341507392, 'mean_word_length': 2.0868113522537564, 'pattern_counts': {'":': 6, '<': 5, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 6, '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': '7353121', 'n_tokens_mistral': 1702, 'n_tokens_neox': 1555, 'n_words': 263}