Skip to content

Commit

Permalink
Merge pull request #600 from stof/fix_tests
Browse files Browse the repository at this point in the history
Fix the testsuite
  • Loading branch information
stof committed Jun 20, 2023
2 parents 84c9814 + df9269a commit d741b37
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 22 deletions.
12 changes: 12 additions & 0 deletions spec/Prophecy/Comparator/FactorySpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@

namespace spec\Prophecy\Comparator;

use PhpSpec\Exception\Example\SkippingException;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Prophecy\Comparator\Factory;
use SebastianBergmann\Comparator\Factory as BaseFactory;

class FactorySpec extends ObjectBehavior
{
function let()
{
$ref = new \ReflectionClass(BaseFactory::class);

if ($ref->isFinal()) {
throw new SkippingException(sprintf('The deprecated "%s" class cannot be used with sebastian/comparator 5+.', Factory::class));
}
}

function it_extends_Sebastian_Comparator_Factory()
{
$this->shouldHaveType('SebastianBergmann\Comparator\Factory');
Expand Down
38 changes: 16 additions & 22 deletions tests/Doubler/Generator/ClassMirrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

namespace Tests\Prophecy\Doubler\Generator;

use Fixtures\Prophecy\SelfReferencing;
use PHPUnit\Framework\TestCase;
use Prophecy\Doubler\Generator\ClassMirror;
use Prophecy\Doubler\Generator\Node\ArgumentTypeNode;
use Prophecy\Doubler\Generator\Node\ReturnTypeNode;
use Prophecy\Exception\Doubler\ClassMirrorException;
use Prophecy\Exception\InvalidArgumentException;
use Prophecy\Prophet;

class ClassMirrorTest extends TestCase
{
Expand Down Expand Up @@ -454,12 +456,19 @@ function it_doesnt_fail_when_method_is_extended_with_more_params()

/**
* @test
* @doesNotPerformAssertions
*/
function it_doesnt_fail_to_mock_self_referencing_interface()
{
$class = $this->prophesize('Fixtures\Prophecy\SelfReferencing');
$class->reveal();
$mirror = new ClassMirror();

$classNode = $mirror->reflect(null, array(new \ReflectionClass(SelfReferencing::class)));

$method = $classNode->getMethod('__invoke');
$this->assertCount(1, $method->getArguments());

$this->assertEquals(new ArgumentTypeNode(SelfReferencing::class), $method->getArguments()[0]->getTypeNode());

$this->assertEquals(new ReturnTypeNode(SelfReferencing::class), $method->getReturnTypeNode());
}

/**
Expand All @@ -468,9 +477,10 @@ function it_doesnt_fail_to_mock_self_referencing_interface()
function it_changes_argument_names_if_they_are_varying()
{
// Use test doubles in this test, as arguments named ... in the Reflection API can only happen for internal classes
$class = $this->prophesize('ReflectionClass');
$method = $this->prophesize('ReflectionMethod');
$parameter = $this->prophesize('ReflectionParameter');
$prophet = new Prophet();
$class = $prophet->prophesize('ReflectionClass');
$method = $prophet->prophesize('ReflectionMethod');
$parameter = $prophet->prophesize('ReflectionParameter');

if (PHP_VERSION_ID >= 80200) {
$class->isReadOnly()->willReturn(false);
Expand Down Expand Up @@ -595,22 +605,6 @@ public function it_can_double_inherited_self_return_type()
$this->assertEquals(new ReturnTypeNode('Fixtures\Prophecy\AbstractBaseClassWithMethodWithReturnType'), $methodNode->getReturnTypeNode());
}

/**
* @test
*/
public function case_insensitive_method_names()
{
$prophecy = $this->prophesize('ArrayObject');
$prophecy->offsetGet(1)->willReturn(1)->shouldBeCalledTimes(1);
$prophecy->offsetget(2)->willReturn(2)->shouldBeCalledTimes(1);
$prophecy->OffsetGet(3)->willReturn(3)->shouldBeCalledTimes(1);

$arrayObject = $prophecy->reveal();
self::assertSame(1, $arrayObject->offsetGet(1));
self::assertSame(2, $arrayObject->offsetGet(2));
self::assertSame(3, $arrayObject->offsetGet(3));
}

/**
* @test
*/
Expand Down
26 changes: 26 additions & 0 deletions tests/FunctionalTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Tests\Prophecy;

use PHPUnit\Framework\TestCase;
use Prophecy\Prophet;

class FunctionalTest extends TestCase
{
/**
* @test
*/
public function case_insensitive_method_names()
{
$prophet = new Prophet();
$prophecy = $prophet->prophesize('ArrayObject');
$prophecy->offsetGet(1)->willReturn(1)->shouldBeCalledTimes(1);
$prophecy->offsetget(2)->willReturn(2)->shouldBeCalledTimes(1);
$prophecy->OffsetGet(3)->willReturn(3)->shouldBeCalledTimes(1);

$arrayObject = $prophecy->reveal();
self::assertSame(1, $arrayObject->offsetGet(1));
self::assertSame(2, $arrayObject->offsetGet(2));
self::assertSame(3, $arrayObject->offsetGet(3));
}
}

0 comments on commit d741b37

Please sign in to comment.