Skip to content

Commit

Permalink
fix(StubProphecy) add fill in for Prophecy
Browse files Browse the repository at this point in the history
  • Loading branch information
lucatume committed Apr 8, 2020
1 parent 7aee6f2 commit feea237
Show file tree
Hide file tree
Showing 45 changed files with 3,971 additions and 1,006 deletions.
9 changes: 9 additions & 0 deletions dynamicReturnTypeMeta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"methodCalls": [
{
"class": "\\tad\\WPBrowser\\Traits\\WithStubProphecy",
"method": "stubProphecy",
"position": 0
}
]
}
23 changes: 12 additions & 11 deletions src/Codeception/Module/WPFilesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
use Codeception\Exception\ModuleConfigException;
use Codeception\Exception\ModuleException;
use Codeception\TestInterface;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\Assert as PHPUnitAssert;
use tad\WPBrowser\Adapters\PHPUnit\Framework\Assert;
use tad\WPBrowser\Filesystem\Utils;
use function tad\WPBrowser\buildDate;
use function tad\WPBrowser\rrmdir;
Expand Down Expand Up @@ -220,7 +221,7 @@ public function amInUploadsPath($path = null)
public function seeUploadedFileFound($filename, $date = null)
{
$path = $this->getUploadsPath($filename, $date);
Assert::assertFileExists($path);
PHPUnitAssert::assertFileExists($path);
}

/**
Expand Down Expand Up @@ -294,7 +295,7 @@ protected function buildDateFrag($date)
*/
public function dontSeeUploadedFileFound($file, $date = null)
{
Assert::assertFileNotExists($this->getUploadsPath($file, $date));
Assert::assertFileDoesNotExist($this->getUploadsPath($file, $date));
}

/**
Expand All @@ -315,7 +316,7 @@ public function dontSeeUploadedFileFound($file, $date = null)
*/
public function seeInUploadedFile($file, $contents, $date = null)
{
Assert::assertStringEqualsFile(
PHPUnitAssert::assertStringEqualsFile(
$this->getUploadsPath(
$file,
$date
Expand All @@ -342,7 +343,7 @@ public function seeInUploadedFile($file, $contents, $date = null)
*/
public function dontSeeInUploadedFile($file, $contents, $date = null)
{
Assert::assertStringNotEqualsFile(
PHPUnitAssert::assertStringNotEqualsFile(
$this->getUploadsPath(
$file,
$date
Expand Down Expand Up @@ -611,7 +612,7 @@ public function seePluginFileFound($file)
*/
public function seeInPluginFile($file, $contents)
{
Assert::assertStringEqualsFile(
PHPUnitAssert::assertStringEqualsFile(
$this->config['plugins'] . Utils::unleadslashit($file),
$contents
);
Expand All @@ -630,7 +631,7 @@ public function seeInPluginFile($file, $contents)
*/
public function dontSeeInPluginFile($file, $contents)
{
Assert::assertStringNotEqualsFile(
PHPUnitAssert::assertStringNotEqualsFile(
$this->config['plugins'] . Utils::unleadslashit($file),
$contents
);
Expand Down Expand Up @@ -764,7 +765,7 @@ public function seeThemeFileFound($file)
*/
public function seeInThemeFile($file, $contents)
{
Assert::assertStringEqualsFile(
PHPUnitAssert::assertStringEqualsFile(
$this->config['themes'] . Utils::unleadslashit($file),
$contents
);
Expand All @@ -783,7 +784,7 @@ public function seeInThemeFile($file, $contents)
*/
public function dontSeeInThemeFile($file, $contents)
{
Assert::assertStringNotEqualsFile(
PHPUnitAssert::assertStringNotEqualsFile(
$this->config['themes'] . Utils::unleadslashit($file),
$contents
);
Expand Down Expand Up @@ -915,7 +916,7 @@ public function seeMuPluginFileFound($file)
*/
public function seeInMuPluginFile($file, $contents)
{
Assert::assertStringEqualsFile(
PHPUnitAssert::assertStringEqualsFile(
$this->config['mu-plugins'] . Utils::unleadslashit($file),
$contents
);
Expand All @@ -934,7 +935,7 @@ public function seeInMuPluginFile($file, $contents)
*/
public function dontSeeInMuPluginFile($file, $contents)
{
Assert::assertStringNotEqualsFile(
PHPUnitAssert::assertStringNotEqualsFile(
$this->config['mu-plugins'] . Utils::unleadslashit($file),
$contents
);
Expand Down
46 changes: 46 additions & 0 deletions src/tad/WPBrowser/Adapters/PHPUnit/Framework/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,50 @@ public static function assertStringNotContainsString($needle, $haystack)
PHPUnitAssert::assertNotContains($needle, $haystack);
}
}

/**
* Adapter and proxy for the `assertFileDoesNotExist` method.
*
* @param string $file The file to check.
*/
public static function assertFileDoesNotExist($file)
{
if (method_exists(PHPUnitAssert::class, 'assertFileDoesNotExist')) {
PHPUnitAssert::assertFileDoesNotExist($file);
} else {
PHPUnitAssert::assertFileNotExists($file);
}
}

/**
* Adapter and proxy for the `assertMatchesRegularExpression` method.
*
* @param string $pattern The regex pattern to match.
* @param string $string The string to check.
* @param string $message The failure message.
*/
public static function assertMatchesRegularExpression($pattern, $string, $message = '')
{
if (method_exists(PHPUnitAssert::class, 'assertMatchesRegularExpression')) {
PHPUnitAssert::assertMatchesRegularExpression($pattern, $string, $message);
} else {
PHPUnitAssert::assertRegExp($pattern, $string, $message);
}
}

/**
* Adapter and proxy for the `assertDoesNotMatchRegularExpression` method.
*
* @param string $pattern The regex pattern to not match.
* @param string $string The string to check.
* @param string $message The failure message.
*/
public static function assertDoesNotMatchRegularExpression($pattern, $string, $message = '')
{
if (method_exists(PHPUnitAssert::class, 'assertDoesNotMatchRegularExpression')) {
PHPUnitAssert::assertDoesNotMatchRegularExpression($pattern, $string, $message);
} else {
PHPUnitAssert::assertNotRegExp($pattern, $string, $message);
}
}
}
4 changes: 3 additions & 1 deletion src/tad/WPBrowser/Events/EventDispatcherAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ public static function setFallbackAvailable($fallbackAvailable)
* @param object|SymfonyEvent|null $originOrEvent The event origin or, in the case of events dispatched by
* Codeception, the original dispatched event.
* @param array $context Additional context or data for the event.
*
* @return object The passed $event MUST be returned
*/
public function dispatch($eventName, $originOrEvent = null, array $context = [])
{
Expand All @@ -334,7 +336,7 @@ public function dispatch($eventName, $originOrEvent = null, array $context = [])
[ $eventObject, $eventName ]
: [ $eventName, $eventObject ];

$this->eventDispatcher->dispatch(...$dispatchArgs);
return $this->eventDispatcher->dispatch(...$dispatchArgs);
}

/**
Expand Down
12 changes: 2 additions & 10 deletions src/tad/WPBrowser/Iterators/Filters/MainStatementQueriesFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace tad\WPBrowser\Iterators\Filters;

use Iterator;
use function tad\WPBrowser\isRegex;

class MainStatementQueriesFilter extends \FilterIterator
{
Expand Down Expand Up @@ -32,20 +33,11 @@ public function __construct(Iterator $iterator, $statement = 'SELECT')
public function accept()
{
$query = $this->getInnerIterator()->current();
$pattern = $this->isRegex($this->statement) ? $this->statement : '/^' . $this->statement . '/i';
$pattern = isRegex($this->statement) ? $this->statement : '/^' . $this->statement . '/i';
if (!preg_match($pattern, $query[0])) {
return false;
}

return true;
}

private function isRegex($statement)
{
try {
return preg_match($statement, null) !== false;
} catch (\Exception $e) {
return false;
}
}
}
Loading

0 comments on commit feea237

Please sign in to comment.