<commit_before><?php
/*
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * This software consists of voluntary contributions made by many individuals
 * and is licensed under the MIT license.
 */

namespace StrictPhpTest\Aspect;

use ReflectionMethod;
use ReflectionProperty;
use StrictPhp\AccessChecker\ParameterTypeChecker;
use Go\Aop\Intercept\MethodInvocation;

/**
 * Tests for {@see \StrictPhp\AccessChecker\ParameterTypeChecker}
 *
 * @author <NAME> <<EMAIL>>
 * @license MIT
 *
 * @group Coverage
 *
 * @covers \StrictPhp\AccessChecker\ParameterTypeChecker
 */
class ParameterTypeCheckerTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var ParameterTypeChecker
     */
    private $parameterCheck;

    /**
     * {@inheritDoc}
     */
    protected function setUp()
    {
        $this->parameterCheck = new ParameterTypeChecker();
    }

    public function testParameterTypeChecker()
    {
        /** @var MethodInvocation|\PHPUnit_Framework_MockObject_MockObject $method */
        $method = $this->getMock(MethodInvocation::class);

        /** @var ReflectionMethod|\PHPUnit_Framework_MockObject_MockObject $reflectionMethod */
        $reflectionMethod = $this->getMockBuilder(ReflectionMethod::class)->disableOriginalConstructor()->getMock();
        /** @var ReflectionProperty|\PHPUnit_Framework_MockObject_MockObject $propertyOne */
        $propertyOne = $this->getMockBuilder(ReflectionProperty::class)->disableOriginalConstructor()->getMock();
        /** @var ReflectionProperty|\PHPUnit_Framework_MockObject_MockObject $propertyTwo */
        $propertyTwo = $this->getMockBuilder(ReflectionProperty::class)->disableOriginalConstructor()->getMock();

        $propertyOne->expects($this->once())->method('getName')->willReturn('parameterOne');
        $propertyTwo->expects($this->once())->method('getName')->willReturn('parameterTwo');

        $properties = [
            $propertyOne,
            $propertyTwo,
        ];

        $reflectionMethod->expects($this->once())->method('getNamespaceName')->willReturn('Application');
        $reflectionMethod->expects($this->once())->method('getParameters')->willReturn($properties);
        $reflectionMethod->expects($this->once())->method('getDeclaringClass')->willReturnSelf();

        $method->expects($this->once())->method('getMethod')->willReturn($reflectionMethod);
        $method->expects($this->once())->method('getArguments')->willReturn($properties);

        $parameterCheck = $this->parameterCheck;
        $parameterCheck($method);
    }<commit_msg>Adapting PHPUnit test to the new DI-based type checker logic<commit_after><?php
/*
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * This software consists of voluntary contributions made by many individuals
 * and is licensed under the MIT license.
 */

namespace StrictPhpTest\Aspect;

use phpDocumentor\Reflection\Type;
use ReflectionMethod;
use ReflectionParameter;
use stdClass;
use StrictPhp\AccessChecker\ParameterTypeChecker;
use Go\Aop\Intercept\MethodInvocation;
use StrictPhpTestAsset\ClassWithMultipleParamsTypedMethodAnnotation;

/**
 * Tests for {@see \StrictPhp\AccessChecker\ParameterTypeChecker}
 *
 * @author <NAME> <<EMAIL>>
 * @license MIT
 *
 * @group Coverage
 *
 * @covers \StrictPhp\AccessChecker\ParameterTypeChecker
 */
class ParameterTypeCheckerTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var ParameterTypeChecker
     */
    private $parameterCheck;

    /**
     * @var callable|\PHPUnit_Framework_MockObject_MockObject
     */
    private $applyTypeChecks;

    /**
     * {@inheritDoc}
     */
    protected function setUp()
    {
        $this->applyTypeChecks = $this->getMock(stdClass::class, ['__invoke']);
        $this->parameterCheck  = new ParameterTypeChecker($this->applyTypeChecks);
    }

    public function testParameterTypeChecker()
    {
        /** @var MethodInvocation|\PHPUnit_Framework_MockObject_MockObject $method */
        $method = $this->getMock(MethodInvocation::class);

        $reflectionMethod = new ReflectionMethod(ClassWithMultipleParamsTypedMethodAnnotation::class, 'method');

        $method->expects($this->once())->method('getMethod')->willReturn($reflectionMethod);
        $method->expects($this->once())->method('getArguments')->willReturn(['foo', 'bar']);

        $parameterCheck = $this->parameterCheck;

        $this
            ->applyTypeChecks
            ->expects($this->exactly(2))
            ->method('__invoke')
            ->with(
                // @todo stricter check here
                $this->callback(function (array $types) {
                    return (bool) array_map(
                        function (Type $type) {
                            return $type;
                        },
                        $types
                    );
                }),
                $this->logicalOr('foo', 'bar')
            );

        $parameterCheck($method);
    }
{'fraction_non_alphanumeric': 0.11242788086698893, 'fraction_numerical': 0.0001559332605644784, 'mean_word_length': 3.5424929178470257, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 70, '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': '416703', 'n_tokens_mistral': 1742, 'n_tokens_neox': 1641, 'n_words': 443}