Skip to content

Instantly share code, notes, and snippets.

@glensc
Last active August 29, 2015 14:00
Show Gist options
  • Save glensc/11341126 to your computer and use it in GitHub Desktop.
Save glensc/11341126 to your computer and use it in GitHub Desktop.
/vendor/
/bin/
/composer.phar
*~
*.sw[op]

reproducer for propelorm/Propel2#623

git clone https://gist.github.com/glensc/11341126 bookstore
cd bookstore
make
phpunit
<?php
// setup the autoloading
require_once __DIR__ . '/vendor/autoload.php';
use Propel\Runtime\Propel;
use Propel\Runtime\Connection\ConnectionManagerSingle;
$serviceContainer = Propel::getServiceContainer();
$serviceContainer->setAdapterClass('bookstore', 'mysql');
$manager = new ConnectionManagerSingle();
$manager->setConfiguration(array (
'dsn' => 'mysql:host=localhost;dbname=bookstore',
'user' => 'mysql',
'password' => '',
));
$serviceContainer->setConnectionManager('bookstore', $manager);
{
"config": {
"bin-dir": "bin"
},
"autoload": {
"classmap": ["generated-classes/"]
},
"require": {
"propel/propel": "2.0.x-dev"
}
}
PROPEL:=./bin/propel
COMPOSER:=composer
all: composer sql model database
sql: generated-sql
composer: composer.lock
composer.lock:
install -d generated-classes
$(COMPOSER) install --no-dev --prefer-dist
generated-sql:
$(PROPEL) sql:build --input-dir=.
model: generated-classes/Book.php
generated-classes/Book.php:
$(PROPEL) model:build --input-dir=.
$(COMPOSER) dumpautoload
database: database.stamp sql
database.stamp:
mysqladmin create bookstore
mysql bookstore < generated-sql/bookstore.sql
touch $@
<?php
use Propel\Runtime\Propel;
use Propel\Runtime\ActiveQuery\ModelCriteria;
class MemoryLeakTest extends PhpUnit_Framework_TestCase {
/** @test */
public function fillDatabase() {
$lock = __DIR__ . '/'. __FUNCTION__ . '.lock';
if (is_file($lock)) {
$this->markTestSkipped('already filled database');
}
system("make", $rc);
$this->assertEquals(0, $rc);
$count = 30;
$publisher = new Publisher();
for ($i = 1; $i < $count; $i++) {
$author = new Author();
$book = new Book();
$book->setAuthor($author);
$book->setPublisher($publisher);
$book->save();
}
file_put_contents($lock, time());
}
public function testLeakage() {
Propel::disableInstancePooling();
$books = BookQuery::create()->setFormatter(ModelCriteria::FORMAT_ON_DEMAND);
echo "Found: ", $books->count(), " rows\n";
foreach ($books as $book) {
$mem = memory_get_usage();
$res = BookQuery::create()->filterByAuthor($book->getAuthor());
$count = $res->count();
$has = $count > 0;
$mem = memory_get_usage() - $mem;
echo "DIFF ($count): $mem\n";
unset($book);
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!-- http://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="Bootstrap.php">
<testsuites>
<testsuite name="My Test Suite">
<file>MemoryLeakTest.php</file>
</testsuite>
</testsuites>
</phpunit>
<?xml version="1.0" encoding="UTF-8"?>
<database name="bookstore" defaultIdMethod="native">
<table name="book" phpName="Book">
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true"/>
<column name="title" type="varchar" size="255" required="true" />
<column name="isbn" type="varchar" size="24" required="true" phpName="ISBN"/>
<column name="publisher_id" type="integer" required="true"/>
<column name="author_id" type="integer" required="true"/>
<foreign-key foreignTable="publisher" phpName="Publisher" refPhpName="Book">
<reference local="publisher_id" foreign="id"/>
</foreign-key>
<foreign-key foreignTable="author">
<reference local="author_id" foreign="id"/>
</foreign-key>
</table>
<table name="author" phpName="Author">
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true"/>
<column name="first_name" type="varchar" size="128" required="true"/>
<column name="last_name" type="varchar" size="128" required="true"/>
</table>
<table name="publisher" phpName="Publisher">
<column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
<column name="name" type="varchar" size="128" required="true" />
</table>
</database>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment