Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

namespace Rector\PHPUnit\Tests\PHPUnit120\Rector\CallLike\CreateStubOverCreateMockArgRector\Fixture;

use PHPUnit\Framework\TestCase;

final class HandleArgumentNotStored extends TestCase
{
public function testThat()
{
$this->useItem($this->createMock(\stdClass::class));

$service = new ServiceWithItem($this->createMock(\stdClass::class));
$service->setItem($this->createMock(\stdClass::class));
ServiceWithItem::create($this->createMock(\stdClass::class));
}

private function useItem($item): void
{
$this->assertInstanceOf(\stdClass::class, $item);
}
}

final class ServiceWithItem
{
private $item;

public function __construct($item)
{
$this->item = $item;
}

public function setItem($item): void
{
$this->item = $item;
}

public static function create($item): self
{
$self = new self(null);
$self->item = $item;

return $self;
}
}

?>
-----
<?php

namespace Rector\PHPUnit\Tests\PHPUnit120\Rector\CallLike\CreateStubOverCreateMockArgRector\Fixture;

use PHPUnit\Framework\TestCase;

final class HandleArgumentNotStored extends TestCase
{
public function testThat()
{
$this->useItem($this->createStub(\stdClass::class));

$service = new ServiceWithItem($this->createStub(\stdClass::class));
$service->setItem($this->createStub(\stdClass::class));
ServiceWithItem::create($this->createStub(\stdClass::class));
}

private function useItem($item): void
{
$this->assertInstanceOf(\stdClass::class, $item);
}
}

final class ServiceWithItem
{
private $item;

public function __construct($item)
{
$this->item = $item;
}

public function setItem($item): void
{
$this->item = $item;
}

public static function create($item): self
{
$self = new self(null);
$self->item = $item;

return $self;
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Rector\PHPUnit\Tests\PHPUnit120\Rector\CallLike\CreateStubOverCreateMockArgRector\Fixture;

use Rector\PHPUnit\Tests\PHPUnit120\Rector\CallLike\CreateStubOverCreateMockArgRector\Source\AbstractTestCaseWithItem;

final class SkipArgumentStoredInParentProperty extends AbstractTestCaseWithItem
{
public function testThat()
{
$this->setUpItem($this->createMock(\stdClass::class));

$this->item->expects($this->once())->method('someMethod');
}

public function testParentCall()
{
parent::setUpItem($this->createMock(\stdClass::class));

$this->item->expects($this->once())->method('someMethod');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Rector\PHPUnit\Tests\PHPUnit120\Rector\CallLike\CreateStubOverCreateMockArgRector\Fixture;

use PHPUnit\Framework\TestCase;

final class SkipArgumentStoredInProperty extends TestCase
{
private $item;

private array $items = [];

public function testThat()
{
$this->setItem($this->createMock(\stdClass::class));

$this->item->expects($this->once())->method('someMethod');
}

public function testVariadic()
{
$this->setItems($this->createMock(\stdClass::class), $this->createMock(\stdClass::class));

$this->items[1]->expects($this->once())->method('someMethod');
}

public function testNamedArgument()
{
$this->setItemWithDefault(item: $this->createMock(\stdClass::class));

$this->item->expects($this->once())->method('someMethod');
}

private function setItem($item): void
{
$this->item = $item;
}

private function setItemWithDefault($name = null, $item = null): void
{
$this->item = $item ?? new \stdClass();
}

private function setItems(...$items): void
{
$this->items = $items;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Rector\PHPUnit\Tests\PHPUnit120\Rector\CallLike\CreateStubOverCreateMockArgRector\Fixture;

use PHPUnit\Framework\TestCase;

final class SkipArrayItemInAnonymousClass extends TestCase
{
public function testThat()
{
$factory = new class {
public function build(): array
{
return [$this->createMock('item')];
}

private function createMock(string $name): string
{
return $name;
}
};

$this->assertSame(['item'], $factory->build());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Rector\PHPUnit\Tests\PHPUnit120\Rector\CallLike\CreateStubOverCreateMockArgRector\Fixture;

use PHPUnit\Framework\TestCase;

final class SkipArrayItemStoredInProperty extends TestCase
{
private array $arguments;

protected function setUp(): void
{
$this->arguments = [
'item' => $this->createMock(\stdClass::class),
];

$this->arguments['nested'] = [
'item' => $this->createMock(\stdClass::class),
];
}

public function testThat()
{
['item' => $item] = $this->arguments;

$item->expects($this->once())->method('someMethod');
$this->arguments['nested']['item']->expects($this->once())->method('someMethod');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Rector\PHPUnit\Tests\PHPUnit120\Rector\CallLike\CreateStubOverCreateMockArgRector\Source;

use PHPUnit\Framework\TestCase;

abstract class AbstractTestCaseWithItem extends TestCase
{
protected $item;

protected function setUpItem($item): void
{
$this->item = $item;
}
}
Loading
Loading