chriskite / phactory Goto Github PK
View Code? Open in Web Editor NEWA Database Factory for PHP Unit Tests
Home Page: http://phactory.org
License: MIT License
A Database Factory for PHP Unit Tests
Home Page: http://phactory.org
License: MIT License
Why does this fail?
# User
Phactory::define('user', array(
'user_name_first' => 'Test_$n',
'user_name_last' => 'User_$n',
'user_name_display' => 'Testerman_$n',
'user_type' => 'Tester',
));
# Montage
Phactory::define('montage',
array(
'theme_id' => 1,
'featured' => '$n'
),
array (
'user_id' => Phactory::oneToOne('user', 'user_id', 'user_id')
)
);
# Cast
Phactory::define('cast',
array(
'active' => true,
'joined_date_start' => $this->now()
),
array(
'user_id' => Phactory::manyToOne('user'),
'montage_id' => Phactory::oneToOne('montage', 'montage_id',
'montage_id'),
));
# Create three users
$user1 = Phactory::create('user');
$user2 = Phactory::create('user');
$user3 = Phactory::create('user');
# Create one montage for $user1 to make him cast leader
$montage = Phactory::createWithAssociations('montage',
array('user_id' => $user1));
# Create the cast
$cast = Phactory::createWithAssociations('cast',
array('user_id' => $user2, 'montage_id' => $montage));
ErrorException: strpos() expects parameter 1 to be string, object given
/usr/share/php/Phactory/lib/Phactory/Blueprint.php:146
/usr/share/php/Phactory/lib/Phactory/Blueprint.php:76
/usr/share/php/Phactory/lib/Phactory/Blueprint.php:96
/usr/share/php/Phactory/lib/Phactory.php:110
/home/mark/dev/projects/cameo/cameo-api/tests/includes/Table/NotificationTest.php:19
When calling isset(), it doesn't look like the model is implementing the magic method __isset() to look in _storage for the value.
Phactory::define('users', array('uid'=>'$n'));
$user = Phactory::create('users', array('uid'=>1));
var_dump($user->uid); // string(1) "1"
var_dump(isset($user->uid)); // bool(false)
Hey, not sure, but I think your website has been hacked and replaced with wedding planning?
Our system uses table prefixes and Phactory has no way that I could find to add the prefix for table names
http://phactory.org/download/ contains at least 2 links that are dead: PearHub && Source Code
the latest version is 0.4.3 ( if i'm not wrong ) yet the website specifies 0.1.0 ...
Referring to the patch here: #14
This is great for fixing table names that are reserved words (although this really should be avoided in the first place IMO), but it causes issues when working and testing with multiple databases.
If using a multi-database set-up the syntax "database_name.table_name" doesn't work with surrounding backticks, as it treats the whole expression as a table name.
I'm having to revert this patch on my copy to get it working, is there a workaround to this?
Perhaps maintaining a list of reserved words and escaping those explicitly, or detecting and seperating expressions containing a '.', although this would genuine table names containing a fullstop/period.. or alternatively modding the code to allow you to specify database as a separate argument?
You cant use this "as is" with composer. This was something I could not find in the documentation. You must have the following "use" keyword
use Phactory\Sql\Phactory;
at the beginning of your file if you want to use it as it is currently documented. You will get the following error otherwise:
Fatal error: Class 'Phactory' not found in ...
I was really excited to use this library in my unit tests... until none of it really worked. The documentation is horribly outdated. I appreciate the attempt made to make this a composer package, however it does not work at all, and I constantly keep getting errors as I "fix" one item after another.
Hi Chris,
I have a bit of annoyance when using Phactory in Eclipse and a few other IDE's. The Phactory::define() method doesn't validate since Eclipse thinks that we are trying to call php's native define().
I am going to submit a pull request/patch that aliases the Phactory::define() method defineBlueprint(). In my honest opinion define() was not the best naming choice in your otherwise awesome component.
Possible solution:
Change in Phactory_Blueprint:
$assoc_keys[$fk_column] = $row->getId();
to
$assoc_keys[$fk_column] = $row->{$association->getToColumn()};
I'm evaluating Phactory to create PHPUnit tests on a project that uses a pre-Cake 2.0 version CakePHP. When I first pulled it down I was getting errors that the Inflector class conflicts with the Inflector class in CakePHP. This made it impossible to use the pear'd version.
I've renamed the class locally to Inflector_p for evaluation purposes, but it might be worth adding a namespace or changing the name to something less common to avoid issues like this.
It would be nice to pass conditions to the get.
Like if I wanted to get the latest created user:
Phactory::get('user', array('name' => 'testuser'), array(
'order' => 'id DESC',
'limit' => 1,
);
For example, this should work:
Phactory::define('tag');
Phactory::define('post',
array('name' => 'Test Blog Post'),
array('tag' => Phactory::manyToMany('tag', 'posts_tags')));
$tag1 = Phactory::create('tag', array('name' => 'PHP'));
$tag1 = Phactory::create('tag', array('name' => 'Testing'));
$post = Phactory::createWithAssociations('post', array('tag' => array($tag1, $tag2)));
Existing functionality should be retained for backwards-compatibility.
Phactory_Blueprint will always pluralize the table.
Hey does this support UUIDs instead of Integers. The read me under "Limitations" says Integer, what about Unique UUID. Much more common now than INT.
Hi chriskite.
I like this idea so much for relieving pain with DB testing.
By the way, I hit problem when requiring Phactory classes with PHPUnit.
I surely specified correct path to 'Phactory.php', but following error was appeard:
{{{
Fatal error: Class 'Phactory' not found in C:\work\scripts\excercise\src\tests\class\models\excerciseTest.php on line 26
}}}
Finally, I found that the problem is solved by rewriting all "<?" to "<?php".
It seems php short tags cause this problem.
It will need to be fixed.
Hello,
If installing Phactory via PEAR, there is no PhactoryMongo.php in package.
Regards, Fred
Using phactory with mongo 2.6.5 and Apache mongo driver 1.5.6 i'm getting following error
MongoCollection::insert(): The 'safe' option is deprecated, please use 'w' instead
Temporal fix was to change 'safe' with 'w' on file Blueprint.php on line 91
//Given:
Phactory::define('keys', array('Xid' => 9999999));
Phactory::create('keys');
// This FAILS to find the record:
...
$keysCollection = $udb->selectCollection('keys');
$keyResults = $keysCollection->findOne(array('Xid' => 9999999));
// However - if we simply change the data (stored and searched) to STRING it works!
Phactory::define('keys', array('Xid' => "9999999"));
Phactory::create('keys');
...
$keysCollection = $udb->selectCollection('keys');
$keyResults = $keysCollection->findOne(array('Xid' => "9999999"));
As you can see the number is small enough not to cause any potential Int64 strangeness.
Clearly a bug.
From the code, setConnection, define and create are not static functions but the README and website guide do not reflect that
"Only variables should be passed by reference" in Phactory/lib/Phactory.php:146
Since for testing purpose we check phactory writen data in mongo with our own code readden data, we are exposed to race condition.
It happens that Phactory::create use MongoCollection->insert and that '$collection->insert' don't wait for mongod response and our PHP test go on even if the data status is not what we expect. It happens for example on a slow development environnement.
I think Phactory::create should invoke collection->insert with array('safe'=>true) as second argument.
All tests are generating errors like this:
Is there a recommended config to get these tests running? Also there are some deprecated warnings generated by latest PHPUnit.
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.