Skip to content

Commit

Permalink
Use instances instead of mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu authored and phansys committed Jan 22, 2021
1 parent be53d10 commit 1dea724
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions tests/Admin/AdminHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,9 +351,7 @@ public function testAppendFormFieldElement(): void

public function testAppendFormFieldElementWithoutFormFieldDescriptionInAdminAndNoCollectionClass(): void
{
$propertyAccessor = $this->createMock(PropertyAccessor::class);

$helper = new AdminHelper($propertyAccessor);
$helper = new AdminHelper($this->propertyAccessor);

$admin = $this->getMockBuilder(AdminInterface::class)
->addMethods(['hasFormFieldDescription'])
Expand Down Expand Up @@ -415,12 +413,7 @@ public function testAppendFormFieldElementWithoutFormFieldDescriptionInAdminAndN
->method('getRequest')
->willReturnOnConsecutiveCalls($request, $request, $request, null, $request, $request, $request, $request, null, $request);

$foo = $this->createMock(Foo::class);
$propertyAccessor
->method('isReadable')
->with($foo, 'bar')
->willReturn(true)
;
$foo = new Foo();
$admin
->method('hasSubject')
->willReturn(true);
Expand Down Expand Up @@ -453,9 +446,7 @@ public function testAppendFormFieldElementWithoutFormFieldDescriptionInAdminAndN

public function testAppendFormFieldElementWithCollection(): void
{
$propertyAccessor = $this->createMock(PropertyAccessor::class);

$helper = new AdminHelper($propertyAccessor);
$helper = new AdminHelper($this->propertyAccessor);

$admin = $this->getMockBuilder(AdminInterface::class)
->addMethods(['hasFormFieldDescription'])
Expand Down Expand Up @@ -517,18 +508,25 @@ public function testAppendFormFieldElementWithCollection(): void
->method('getRequest')
->willReturnOnConsecutiveCalls($request, $request, $request, null, $request, $request, $request, $request, null, $request);

$foo = $this->createMock(Foo::class);
$propertyAccessor
->method('isReadable')
->with($foo, 'bar')
->willReturn(true)
;
$propertyAccessor
->expects($this->once())
->method('getValue')
->with($foo, 'bar')
->willReturn(new ArrayCollection())
;
$foo = new class() {
private $bar;

public function __construct()
{
$this->bar = new ArrayCollection();
}

public function getBar(): Collection
{
return $this->bar;
}

public function setBar(Collection $bar): void
{
$this->bar = $bar;
}
};

$admin
->method('hasSubject')
->willReturn(true);
Expand Down

0 comments on commit 1dea724

Please sign in to comment.