Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

make class targets selectable #276

Merged
merged 2 commits into from

2 participants

Toni Uebernickel William Durand
Toni Uebernickel

This enables usage of the QuickBuilder in test environments where parts of those classes are given and others are not (like having the Book committed but not adding the BaseBook into VCS).

Real-world usage example:

<?php

/**
 * This file is part of the PropelBundle package.
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @license    MIT License
 */

namespace Propel\PropelBundle\Tests\Security\Acl;

use PropelQuickBuilder;

use Propel\PropelBundle\Tests\TestCase as BaseTestCase;

/**
 * @author Toni Uebernickel <tuebernickel@gmail.com>
 */
class TestCase extends BaseTestCase
{
    protected $con = null;

    public function setUp()
    {
        parent::setUp();

        $this->loadPropelQuickBuilder();

        $schema = file_get_contents(__DIR__.'/../../../Resources/config/acl_schema.xml');

        $builder = new PropelQuickBuilder();
        $builder->setSchema($schema);
        if (!class_exists('Propel\PropelBundle\Model\Acl\map\AclClassTableMap')) {
            $builder->setClassTargets(array('tablemap', 'peer', 'object', 'query'));
        } else {
            $builder->setClassTargets(array());
        }

        $this->con = $builder->build();

        return;
    }
}
Toni Uebernickel havvg referenced this pull request in propelorm/PropelBundle
Merged

[Security] AclProvider #100

William Durand
Owner

Makes sense, thanks!

As it's just for unit tests, it's not what we can call a "new feature", so good to merge. Can you write the same PR for Propelé ?

William Durand willdurand merged commit af6994e into from
Toni Uebernickel havvg referenced this pull request in propelorm/Propel2
Merged

make class targets selectable #131

Toni Uebernickel havvg deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 1, 2012
  1. Toni Uebernickel

    make class targets selectable

    havvg authored
  2. Toni Uebernickel
This page is out of date. Refresh to see the latest.
30 generator/lib/util/PropelQuickBuilder.php
View
@@ -15,6 +15,13 @@ class PropelQuickBuilder
{
protected $schema, $platform, $config, $database;
+ protected $classTargets = array('tablemap', 'peer', 'object', 'query', 'peerstub', 'objectstub', 'querystub');
+
+ public function setClassTargets(array $targets)
+ {
+ $this->classTargets = $targets;
+ }
+
public function setSchema($schema)
{
$this->schema = $schema;
@@ -75,7 +82,7 @@ public static function buildSchema($schema, $dsn = null, $user = null, $pass = n
return $builder->build($dsn, $user, $pass, $adapter);
}
- public function build($dsn = null, $user = null, $pass = null, $adapter = null)
+ public function build($dsn = null, $user = null, $pass = null, $adapter = null, array $classTargets = null)
{
if (null === $dsn) {
$dsn = 'sqlite::memory:';
@@ -83,10 +90,13 @@ public function build($dsn = null, $user = null, $pass = null, $adapter = null)
if (null === $adapter) {
$adapter = new DBSQLite();
}
+ if (null === $classTargets) {
+ $classTargets = $this->classTargets;
+ }
$con = new PropelPDO($dsn, $user, $pass);
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$this->buildSQL($con);
- $this->buildClasses();
+ $this->buildClasses($classTargets);
$name = $this->getDatabase()->getName();
if (!Propel::isInit()) {
Propel::setConfiguration(array('datasources' => array('default' => $name)));
@@ -129,25 +139,29 @@ public function getSQL()
return $this->getPlatform()->getAddTablesDDL($this->getDatabase());
}
- public function buildClasses()
+ public function buildClasses(array $classTargets = null)
{
- eval($this->getClasses());
+ eval($this->getClasses($classTargets));
}
- public function getClasses()
+ public function getClasses(array $classTargets = null)
{
$script = '';
foreach ($this->getDatabase()->getTables() as $table) {
- $script .= $this->getClassesForTable($table);
+ $script .= $this->getClassesForTable($table, $classTargets);
}
return $script;
}
- public function getClassesForTable(Table $table)
+ public function getClassesForTable(Table $table, array $classTargets = null)
{
+ if (null === $classTargets) {
+ $classTargets = $this->classTargets;
+ }
+
$script = '';
- foreach (array('tablemap', 'peer', 'object', 'query', 'peerstub', 'objectstub', 'querystub') as $target) {
+ foreach ($classTargets as $target) {
$script .= $this->getConfig()->getConfiguredBuilder($table, $target)->build();
}
14 test/testsuite/generator/util/PropelQuickBuilderTest.php
View
@@ -101,6 +101,20 @@ public function testBuildClasses($builder)
$this->assertTrue(QuickBuildFoo1Peer::getTableMap() instanceof QuickBuildFoo1TableMap);
}
+ /**
+ * @dataProvider simpleSchemaProvider
+ */
+ public function testGetClassesLimitedClassTargets($builder)
+ {
+ $script = $builder->getClasses(array('tablemap', 'peer', 'object', 'query'));
+ $this->assertNotContains('class QuickBuildFoo1 extends BaseQuickBuildFoo1', $script);
+ $this->assertNotContains('class QuickBuildFoo1Peer extends BaseQuickBuildFoo1Peer', $script);
+ $this->assertNotContains('class QuickBuildFoo1Query extends BaseQuickBuildFoo1Query', $script);
+ $this->assertContains('class BaseQuickBuildFoo1 extends BaseObject', $script);
+ $this->assertContains('class BaseQuickBuildFoo1Peer', $script);
+ $this->assertContains('class BaseQuickBuildFoo1Query extends ModelCriteria', $script);
+ }
+
public function testBuild()
{
$schema = <<<EOF
Something went wrong with that request. Please try again.