CounterpartHandlerTest.php 1.54 KB
Newer Older
1 2 3 4 5 6 7
<?php

namespace LQDN\Tests\Functional\Handler;

use LQDN\Command\CounterpartCreateCommand;
use LQDN\Command\CounterpartDeleteCommand;
use LQDN\Command\CounterpartChangeStateCommand;
8
use LQDN\Command\AdminUpdateParentCommand;
9 10 11 12 13
use LQDN\Handler\CounterpartHandler;
use LQDN\Tests\Functional\FunctionalTest;

class CounterpartHandlerTest extends FunctionalTest
{
14 15 16 17
    public function testAdminUpdateParentCommand()
    {
        $this->container['command_handler']->handle(new AdminUpdateParentCommand());
        $target = $this->container['counterpart_finder']->findById(4);
18
        $this->assertSame((int) $target['parent'], 4);
19 20
    }

21 22 23 24 25 26 27 28 29
    public function testCounterpartDelete()
    {
        $this->assertTrue($this->counterpartExists(1));

        $this->container['command_handler']->handle(new CounterpartDeleteCommand(1));
    }

    public function testCounterpartCreate()
    {
30
        $this->assertFalse($this->counterpartExists(5));
31

32
        $this->container['command_handler']->handle(new CounterpartCreateCommand(1, 1, 'pishirt', 4, 1, date("Y-m-d H:i:s"), '', 1));
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
    }

    public function testCounterpartChangeState()
    {
        $this->assertTrue($this->counterpartExists(1));

        $this->container['command_handler']->handle(new CounterpartChangeStateCommand(1, 2));
    }

    /**
     * Check if a counterpart exists in BDD
     *
     * @param int $id
     *
     * @return bool
     */
    private function counterpartExists($id)
    {
        return (bool) $this->container['db']->fetchColumn("SELECT 1 FROM contreparties WHERE id = $id");
    }
}