<commit_before><?php

use Autodns\Api\Client\Method\Provider;
use Autodns\Api\XmlDelivery;

class ClientTest extends TestCase
{
    const SOME_URL = 'some url';

    const SOME_METHOD_NAME = 'some method name';

    /**
     * @var Provider | TestDataBuilder_StubBuilder | PHPUnit_Framework_MockObject_MockObject
     */
    private $methodProvider;

    /**
     * @var XmlDelivery | TestDataBuilder_StubBuilder | PHPUnit_Framework_MockObject_MockObject
     */
    private $delivery;

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

        $this->methodProvider = $this->aStub('Autodns\Api\Client\Method\Provider')
            ->with('fetchMethod', $this->aMethod());
        $this->delivery = $this->aStub('Autodns\Api\XmlDelivery');
    }

    /**
     * @test
     */
    public function itShouldFetchTheMethodByTheMethodName()
    {
        $methodName = self::SOME_METHOD_NAME;

        $this->methodProvider = $this->methodProvider->build();
        $this->methodProvider
            ->expects($this->once())
            ->method('fetchMethod')
            ->with($methodName);

        $this->buildClient()->call($methodName, self::SOME_URL, $this->somePayload());
    }

    /**
     * @test
     */
    public function itShouldCreateATaskWithTheFetchedMethod()
    {
        $payload = $this->somePayload();

        $method = $this->aMethod()->build();
        $method
            ->expects($this->once())
            ->method('createTask')
            ->with($payload);

        $this->methodProvider->with('fetchMethod', $method);

        $this->buildClient()->call(self::SOME_METHOD_NAME, self::SOME_URL, $payload);
    }

    /**
     * @test
     */
    public function itShouldSendTheRequestToTheGivenUrl()
    {
        $url = self::SOME_URL;

        $this->delivery = $this->delivery->build();
        $this->delivery
            ->expects($this->once())
            ->method('send')
            ->with($url, $this->anything());

        $this->buildClient()->call(self::SOME_METHOD_NAME, $url, $this->somePayload());
    }

    /**
     * @test
     */
    public function itShouldReturnTheResponseFromTheDelivery()
    {
        $response = 'some response';

        $this->delivery->with('send', $response);

        $this->assertSame($response, $this->buildClient()->call(self::SOME_METHOD_NAME, self::SOME_URL, $this->somePayload()));
    }

    /**
     * @return \Autodns\Api\Client
     */
    private function buildClient()
    {
        return $this->anObject('\Autodns\Api\Client')
            ->with(
                array(
                    $this->methodProvider,
                    $this->delivery
                )
            )->build();
    }

    private function somePayload()
    {
        return array();
    }

    /**
     * @return TestDataBuilder_StubBuilder
     */
    private function aMethod()
    {
        return $this->aStub('Autodns\Api\Client\Method')->with('createTask', array());
    }

    private function someRequest()
    {
        return array();
    }
}
<commit_msg>adds test for sending the correct task<commit_after><?php

use Autodns\Api\Client\Method\Provider;
use Autodns\Api\XmlDelivery;

class ClientTest extends TestCase
{
    const SOME_URL = 'some url';

    const SOME_METHOD_NAME = 'some method name';

    /**
     * @var Provider | TestDataBuilder_StubBuilder | PHPUnit_Framework_MockObject_MockObject
     */
    private $methodProvider;

    /**
     * @var XmlDelivery | TestDataBuilder_StubBuilder | PHPUnit_Framework_MockObject_MockObject
     */
    private $delivery;

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

        $this->methodProvider = $this->aStub('Autodns\Api\Client\Method\Provider')
            ->with('fetchMethod', $this->aMethod());
        $this->delivery = $this->aStub('Autodns\Api\XmlDelivery');
    }

    /**
     * @test
     */
    public function itShouldFetchTheMethodByTheMethodName()
    {
        $methodName = self::SOME_METHOD_NAME;

        $this->methodProvider = $this->methodProvider->build();
        $this->methodProvider
            ->expects($this->once())
            ->method('fetchMethod')
            ->with($methodName);

        $this->buildClient()->call($methodName, self::SOME_URL, $this->somePayload());
    }

    /**
     * @test
     */
    public function itShouldCreateATaskWithTheFetchedMethod()
    {
        $payload = $this->somePayload();

        $method = $this->aMethod()->build();
        $method
            ->expects($this->once())
            ->method('createTask')
            ->with($payload);

        $this->methodProvider->with('fetchMethod', $method);

        $this->buildClient()->call(self::SOME_METHOD_NAME, self::SOME_URL, $payload);
    }

    /**
     * @test
     */
    public function itShouldSendTheTaskToTheGivenUrl()
    {
        $url = self::SOME_URL;
        $task = array('some' => 'task');

        $method = $this->aMethod()->with('createTask', $task);
        $this->methodProvider->with('fetchMethod', $method);

        $this->delivery = $this->delivery->build();
        $this->delivery
            ->expects($this->once())
            ->method('send')
            ->with($url, $task);

        $this->buildClient()->call(self::SOME_METHOD_NAME, $url, $this->somePayload());
    }

    /**
     * @test
     */
    public function itShouldReturnTheResponseFromTheDelivery()
    {
        $response = 'some response';

        $this->delivery->with('send', $response);

        $this->assertSame($response, $this->buildClient()->call(self::SOME_METHOD_NAME, self::SOME_URL, $this->somePayload()));
    }

    /**
     * @return \Autodns\Api\Client
     */
    private function buildClient()
    {
        return $this->anObject('\Autodns\Api\Client')
            ->with(
                array(
                    $this->methodProvider,
                    $this->delivery
                )
            )->build();
    }

    private function somePayload()
    {
        return array();
    }

    /**
     * @return TestDataBuilder_StubBuilder
     */
    private function aMethod()
    {
        return $this->aStub('Autodns\Api\Client\Method')->with('createTask', array());
    }

    private function someRequest()
    {
        return array();
    }
}

{'fraction_non_alphanumeric': 0.15572202741472746, 'fraction_numerical': 0.0, 'mean_word_length': 2.254668049792531, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 113, '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': '5979051', 'n_tokens_mistral': 1874, 'n_tokens_neox': 1823, 'n_words': 276}