Skip to content

Commit

Permalink
add testNoPHPUnitMockUsed test
Browse files Browse the repository at this point in the history
  • Loading branch information
keradus committed Oct 6, 2023
1 parent 3b703c9 commit 0c34457
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/AutoReview/ProjectCodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,38 @@ public function testThereIsNoPregFunctionUsedDirectly(string $className): void
self::assertNotContains('preg_split', $strings, $message);
}

/**
* @dataProvider provideTestClassCases
*/
public function testNoPHPUnitMockUsed(string $testClassName): void
{
$rc = new \ReflectionClass($testClassName);
$tokens = Tokens::fromCode(file_get_contents($rc->getFileName()));
$stringTokens = array_filter(
$tokens->toArray(),
static fn (Token $token): bool => $token->isGivenKind(T_STRING)
);

$strings = array_map(
static fn (Token $token): string => $token->getContent(),
$stringTokens
);
$strings = array_unique($strings);

$message = sprintf('Class %s must not use PHPUnit\'s mock,, it shall use ->prophesize() instead.', $testClassName);
self::assertNotContains('getMockBuilder', $strings, $message);
self::assertNotContains('createMock', $strings, $message);
self::assertNotContains('createMockForIntersectionOfInterfaces', $strings, $message);
self::assertNotContains('createPartialMock', $strings, $message);
self::assertNotContains('createTestProxy', $strings, $message);
self::assertNotContains('getMockForAbstractClass', $strings, $message);
self::assertNotContains('getMockFromWsdl', $strings, $message);
self::assertNotContains('getMockForTrait', $strings, $message);
self::assertNotContains('getMockClass', $strings, $message);
self::assertNotContains('createConfiguredMock', $strings, $message);
self::assertNotContains('getObjectForTrait', $strings, $message);
}

/**
* @dataProvider provideTestClassCases
*/
Expand Down

0 comments on commit 0c34457

Please sign in to comment.