Skip to content

Instantly share code, notes, and snippets.

View fzaninotto's full-sized avatar

Francois Zaninotto fzaninotto

View GitHub Profile
@fzaninotto
fzaninotto / gist:1308697
Created October 24, 2011 09:58
Inserting data to several tables using Faker Populator and Propel
<?php
$faker = \Faker\Factory::create();
$populator = new \Faker\ORM\Propel\Populator($faker);
$populator->addEntity('Author', 10000);
$populator->addEntity('Book', 100000);
$populator->addEntity('Review', 1000000);
$insertedPKs = $populator->execute();
@fzaninotto
fzaninotto / gist:1308655
Created October 24, 2011 09:25
Inserting data to a database using Faker Populator and Propel
<?php
$faker = \Faker\Factory::create();
$populator = new \Faker\ORM\Propel\Populator($faker);
$populator->addEntity('Author', 100);
$insertedPKs = $populator->execute();
@fzaninotto
fzaninotto / gist:1308553
Created October 24, 2011 07:55
Inserting data to a database using Faker and Propel
<?php
$faker = \Faker\Factory::create();
$insertedPKs = array();
for ($i=0; $i < 100; $i++) {
$author = new Author();
$author->setFirstName($faker->firstName);
$author->setLastName($faker->lastName);
$author->setDateOfBirth($faker->date);
$author->setEmail($faker->email);
$author->save();
@fzaninotto
fzaninotto / gist:1308547
Created October 24, 2011 07:49
Inserting data to a database using Faker and PDO
<?php
$pdo = new PDO('mysql:host=hostname;dbname=defaultDbName', 'username', 'p@55w0rd');
$sql = 'INSERT INTO author (first_name, last_name, date_of_birth, email) VALUES (?, ?, ?, ?)';
$stmt = $pdo->prepare($sql);
$faker = \Faker\Factory::create();
$insertedPKs = array();
for ($i=0; $i < 100; $i++) {
$stmt->bindValue(1, $faker->firstName, PDO::PARAM_STR);
$stmt->bindValue(2, $faker->lastName, PDO::PARAM_STR);
$stmt->bindValue(1, $faker->date, PDO::PARAM_STR);
@fzaninotto
fzaninotto / gist:1292105
Created October 17, 2011 07:10
Faker first example
<?php
require_once '/path/to/Faker/src/Factory.php';
$faker = Faker\Factory::create(); // $faker is a Faker\Generator instance
echo $faker->name;
// 'Lucy Cechtelar';
echo $faker->address;
// "426 Jordy Lodge
// Cartwrightshire, SC 88120-6700"
echo $faker->lorem;
@fzaninotto
fzaninotto / removeTrailingSpaces.php
Created April 6, 2011 19:19
Remove trailing spaces from PHP source files
<?php
$tests=array();
foreach (new RegexIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__,0|\RecursiveDirectoryIterator::SKIP_DOTS)), '/\.php$/') as $file) {
if (strpos((string) $file, '.svn')) {
continue;
}
$tests[] = realpath((string) $file);
}
foreach ($tests as $file) {
<?php
// Propel way
$books = BookQuery::create()->find();
$xmlBooks = $books->toXml();
// Doctrine way
// $this is a symfony controller having access to the DIC
$em = $this->get('doctrine.orm.entity_manager');
$books = $em->createQuery('select b from \Acme\DemoBundle\Entity\Book b')->getResult();
@fzaninotto
fzaninotto / gist:671706
Created November 10, 2010 23:12
diff for phing's phpunit formatters to make cli output nicer in phinh 2.3.3
diff --git a/phpunit3/PlainPHPUnit3ResultFormatter.php b/phpunit3/PlainPHPUnit3ResultFormatter.php
index f2997aa..a671670 100644
--- a/phpunit3/PlainPHPUnit3ResultFormatter.php
+++ b/phpunit3/PlainPHPUnit3ResultFormatter.php
@@ -52,19 +52,13 @@ class PlainPHPUnit3ResultFormatter extends PHPUnit3ResultFormatter
function endTestSuite(PHPUnit_Framework_TestSuite $suite)
{
- $sb = "Testsuite: " . $suite->getName() . "\n";
- $sb.= "Tests run: " . $this->getRunCount();
<?php
class AggregateColumnBehavior extends Behavior
{
// default parameters value
protected $parameters = array(
'name' =>; null,
);
}
<pre><code>&lt;database name="my_connection_name" defaultIdMethod="native"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://www.propelorm.org/xsd/1.5/database.xsd" &gt;
</code></pre>