lucatume / function-mocker Goto Github PK
View Code? Open in Web Editor NEWA Patchwork powered function mocker.
A Patchwork powered function mocker.
FunctionMocker::replace('\App\Model\Base\XyzUser::save', null);
the Class and Method to redefine
abstract class XyzUser implements ActiveRecordInterface {
public function save(ConnectionInterface $con = null) {
if ($this->isDeleted()) {
throw new PropelException("You cannot save an object that has been deleted.");
}
if ($this->alreadyInSave) {
return 0;
}
if ($con === null) {
$con = Propel::getServiceContainer()->getWriteConnection(EubylonUserTableMap::DATABASE_NAME);
}
return $con->transaction(function () use ($con) {
$ret = $this->preSave($con);
$isInsert = $this->isNew();
if ($isInsert) {
$ret = $ret && $this->preInsert($con);
} else {
$ret = $ret && $this->preUpdate($con);
}
if ($ret) {
$affectedRows = $this->doSave($con);
if ($isInsert) {
$this->postInsert($con);
} else {
$this->postUpdate($con);
}
$this->postSave($con);
EubylonUserTableMap::addInstanceToPool($this);
} else {
$affectedRows = 0;
}
return $affectedRows;
});
}
}
syntax error, unexpected 'public' (T_PUBLIC)
/home/ridaamirini/PhpstormProjects/v2.0/lib/vendor/lucatume/function-mocker/src/tad/FunctionMocker/MockWrapper.php:53
/home/ridaamirini/PhpstormProjects/v2.0/lib/vendor/lucatume/function-mocker/src/tad/FunctionMocker/Replacers/InstanceForger.php:116
/home/ridaamirini/PhpstormProjects/v2.0/lib/vendor/lucatume/function-mocker/src/tad/FunctionMocker/Replacers/InstanceForger.php:42
/home/ridaamirini/PhpstormProjects/v2.0/lib/vendor/lucatume/function-mocker/src/tad/FunctionMocker/FunctionMocker.php:211
/home/ridaamirini/PhpstormProjects/v2.0/lib/vendor/lucatume/function-mocker/src/tad/FunctionMocker/FunctionMocker.php:161
/home/ridaamirini/PhpstormProjects/v2.0/lib/vendor/lucatume/function-mocker/src/tad/FunctionMocker/FunctionMocker.php:142
/home/ridaamirini/PhpstormProjects/v2.0/tests/dev_user/RecoverPasswordTest.php:167
Need to support for PHP8.0
First of all thank you for #3 !
Given the following block:
"require-dev": {
"phpunit/phpunit": "^6.1",
"lucatume/function-mocker": "^1.0"
}
It successfully installs function-mocker: 1.2
and phpunit 6.1
on php 7.1.4
.
But from the config in this repo it shouldn't allow a phpunit version >= 6.0 .
The reason I'm reporting this is because
some imports like PHPUnit_Framework_Assert
will not work in phpunit 6+ (reproducible when calling wasCalledWithOnce
on a redefinition).
Is there any chance that phpunit >=6.0 will be supported?
Maybe on a separate branch, even if features won't be added as often?
Patchwork can redefine for instance time()
calls if a proper entry in patchworks.json is added before patchwork's init. I have the file but for some reason the mocker explicitly checks to see if it is a system function an bails out. Is there a more deeper reason why this is not supported? or it's an artifact of a previous version.
https://github.com/lucatume/function-mocker/blob/master/src/tad/FunctionMocker/Checker.php#L18
I've noticed that in the most recent version of the library, a vendor\lucatume\function-mocker\cache\
folder is created and some cached code is saved there.
This is causing two issues:
Is it possible to make the library cache these files outside the project (e.g. in the default "temp" directory)?
A solution which requires an environment variable (so it can fall back to the current vendor\lucatume\function-mocker\cache\
if the variable is missing) would be also fine.
Hello,
I have a situation, where I check with wasCalledWithOnce
something like this:
$mock_func->wasCalledWithOnce([
0,
[],
[
'key_1' => [
[
'key_1_1' => [
[
'key' => null,
'another_key' => null,
'another_one' => 0
]
]
]
],
'key_2' => 0,
'key_3' => 0,
'key_4' => null,
],
0
]);
It's failing at the third argument, The args values are valid, and I can't see where the issue is.
So my question is: Is there any way I can print the diff between what I give it and what the actual args, like what assertEqual
is doing?
Thanks,
I've stumbled in a project where the vendor directory does not exist (actually, it does exist but with a different name).
\tad\FunctionMocker\Utils::findParentContainingFrom
tries to find the first directory called "vendor" from the current directory and up.
This logic has two consequences:
\tad\FunctionMocker\FunctionMocker::setUp
could accept an optional argument to specify the name of the vendor directory?\tad\FunctionMocker\Utils::findParentContainingFrom
reaches the root directory, it continues forever checking that same root directory.$dir !== ''/'
right before calling $dir = dirname($dir);
and, in this case, gracefully fail.Not a blocking issue for me. The original developers of the project I'm working with, are most likely going to start using the "vendor" directory, as most of the rest of the world :)
I just wanted to report it.
I have a case where I use one function several times in a row. For example, filter_input
. It is not very convenient to use anonymous functions:
public function test_case() {
$answers = [ 'one', 'two' ];
FunctionMocker::replace(
'filter_input',
function () use ($answers) {
static $i = 0;
return $answers[ $i ++ ];
}
);
$this->assertSame(
'one',
filter_input( INPUT_POST, 'first_use', FILTER_SANITIZE_STRING )
);
$this->assertSame(
'two',
filter_input( INPUT_POST, 'second_use', FILTER_SANITIZE_STRING )
);
}
It would be nice to add method replaceInOrder
for a shorter record:
public function test_case() {
FunctionMocker::replaceInOrder( 'filter_input', [ 'one', 'two' ] );
$this->assertSame(
'one',
filter_input( INPUT_POST, 'first_use', FILTER_SANITIZE_STRING )
);
$this->assertSame(
'two',
filter_input( INPUT_POST, 'second_use', FILTER_SANITIZE_STRING )
);
}
I tried to redefine the Method but nothing happens.
FunctionMocker::replace('filter_input','TEST');
$this->assertEquals('Test', filter_input(INPUT_POST, 'name', FILTER_SANITIZE_STRING));
Patchwork.json
{ "redefinable-internals": [ "filter_input", "time" ] }
IMO need to update the dependencies for PHPUnit because 5.2.3 really old)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.