<commit_before><?php

namespace EasyMock\Test;

use EasyMock\EasyMock;
use EasyMock\Test\Fixture\ClassFixture;
use EasyMock\Test\Fixture\CustomException;
use EasyMock\Test\Fixture\InterfaceFixture;

/**
 * @author <NAME> <<EMAIL>>
 */
class MockClassTest extends \PHPUnit_Framework_TestCase
{
    use EasyMock;

    /**
     * @test
     */
    public function should_mock_objects()
    {
        /** @var ClassFixture $mock */
        $mock = $this->easyMock('EasyMock\Test\Fixture\ClassFixture');

        $this->assertInstanceOf('PHPUnit_Framework_MockObject_MockObject', $mock);
        $this->assertNull($mock->foo());
    }

    /**
     * @test
     */
    public function should_mock_interfaces()
    {
        /** @var InterfaceFixture $mock */
        $mock = $this->easyMock('EasyMock\Test\Fixture\InterfaceFixture');

        $this->assertInstanceOf('PHPUnit_Framework_MockObject_MockObject', $mock);
        $this->assertNull($mock->foo());
    }

    /**
     * @test
     */
    public function not_mocked_methods_should_return_null()
    {
        /** @var ClassFixture $mock */
        $mock = $this->easyMock('EasyMock\Test\Fixture\ClassFixture');

        $this->assertNull($mock->foo());
    }

    /**
     * @test
     */
    public function should_mock_existing_method_with_a_value()
    {
        /** @var ClassFixture $mock */
        $mock = $this->easyMock('EasyMock\Test\Fixture\ClassFixture', array(
            'foo' => 'bar',
        ));

        $this->assertSame('bar', $mock->foo());
    }

    /**
     * @test
     */
    public function should_mock_existing_method_with_a_callback()
    {
        /** @var ClassFixture $mock */
        $mock = $this->easyMock('EasyMock\Test\Fixture\ClassFixture', array(
            'foo' => function () {
                return 'bar';
            },
        ));

        $this->assertSame('bar', $mock->foo());
    }

    /**
     * @test
     * @expectedException \EasyMock\Test\Fixture\CustomException
     * @expectedExceptionMessage My message
     */
    public function should_mock_existing_method_to_throw_exception()
    {
        /** @var ClassFixture $mock */
        $mock = $this->easyMock('EasyMock\Test\Fixture\ClassFixture', array(
            'foo' => new CustomException('My message'),
        ));
        $mock->foo();
    }

    /**
     * @test
     */
    public function should_mock_new_methods_on_existing_mock()
    {
        /** @var ClassFixture $mock */
        $mock = $this->easyMock('EasyMock\Test\Fixture\ClassFixture');
        $mock = $this->easyMock($mock, array(
            'foo' => 'bar',
        ));

        $this->assertSame('bar', $mock->foo());
    }

    /**
     * @test
     */
    public function should_allow_to_spy_method_calls()
    {
        $mock = $this->easySpy('EasyMock\Test\Fixture\ClassFixture', array(
            'foo' => 'bar',
        ));

        $this->assertEquals('bar', $mock->foo());
    }
}<commit_msg>Improve test for spy mocks<commit_after><?php

namespace EasyMock\Test;

use EasyMock\EasyMock;
use EasyMock\Test\Fixture\ClassFixture;
use EasyMock\Test\Fixture\CustomException;
use EasyMock\Test\Fixture\InterfaceFixture;

/**
 * @author <NAME> <<EMAIL>>
 */
class MockClassTest extends \PHPUnit_Framework_TestCase
{
    use EasyMock;

    /**
     * @test
     */
    public function should_mock_objects()
    {
        /** @var ClassFixture $mock */
        $mock = $this->easyMock('EasyMock\Test\Fixture\ClassFixture');

        $this->assertInstanceOf('PHPUnit_Framework_MockObject_MockObject', $mock);
        $this->assertNull($mock->foo());
    }

    /**
     * @test
     */
    public function should_mock_interfaces()
    {
        /** @var InterfaceFixture $mock */
        $mock = $this->easyMock('EasyMock\Test\Fixture\InterfaceFixture');

        $this->assertInstanceOf('PHPUnit_Framework_MockObject_MockObject', $mock);
        $this->assertNull($mock->foo());
    }

    /**
     * @test
     */
    public function not_mocked_methods_should_return_null()
    {
        /** @var ClassFixture $mock */
        $mock = $this->easyMock('EasyMock\Test\Fixture\ClassFixture');

        $this->assertNull($mock->foo());
    }

    /**
     * @test
     */
    public function should_mock_existing_method_with_a_value()
    {
        /** @var ClassFixture $mock */
        $mock = $this->easyMock('EasyMock\Test\Fixture\ClassFixture', array(
            'foo' => 'bar',
        ));

        $this->assertSame('bar', $mock->foo());
    }

    /**
     * @test
     */
    public function should_mock_existing_method_with_a_callback()
    {
        /** @var ClassFixture $mock */
        $mock = $this->easyMock('EasyMock\Test\Fixture\ClassFixture', array(
            'foo' => function () {
                return 'bar';
            },
        ));

        $this->assertSame('bar', $mock->foo());
    }

    /**
     * @test
     * @expectedException \EasyMock\Test\Fixture\CustomException
     * @expectedExceptionMessage My message
     */
    public function should_mock_existing_method_to_throw_exception()
    {
        /** @var ClassFixture $mock */
        $mock = $this->easyMock('EasyMock\Test\Fixture\ClassFixture', array(
            'foo' => new CustomException('My message'),
        ));
        $mock->foo();
    }

    /**
     * @test
     */
    public function should_mock_new_methods_on_existing_mock()
    {
        /** @var ClassFixture $mock */
        $mock = $this->easyMock('EasyMock\Test\Fixture\ClassFixture');
        $mock = $this->easyMock($mock, array(
            'foo' => 'bar',
        ));

        $this->assertSame('bar', $mock->foo());
    }

    /**
     * @test
     */
    public function should_allow_to_spy_method_calls()
    {
        $mock = $this->easySpy('EasyMock\Test\Fixture\ClassFixture', array(
            'foo' => 'bar',
        ));

        // Test PHPUnit's internals to check that the spy was registered
        $property = new \ReflectionProperty('PHPUnit_Framework_TestCase', 'mockObjects');
        $property->setAccessible(true);
        $mockObjects = $property->getValue($this);

        $this->assertCount(1, $mockObjects);
        $this->assertSame($mock, $mockObjects[0]);

        // Cannot use @expectedException because PHPUnit has specific behavior for this
        try {
            $mock->__phpunit_verify();
            $this->fail('Exception not thrown');
        } catch (\PHPUnit_Framework_ExpectationFailedException $e) {
            $this->assertContains('Expected invocation at least once but it never occured', $e->getMessage());
        }

        // Invoke the mock: the test should now pass
        $mock->foo();
    }
}
{'fraction_non_alphanumeric': 0.15296769346356123, 'fraction_numerical': 0.00030052592036063113, 'mean_word_length': 2.3447236180904523, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 78, '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': '2064558', 'n_tokens_mistral': 2072, 'n_tokens_neox': 1996, 'n_words': 323}