Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch '2.0'

  • Loading branch information...
commit b019559de8385144c44f5dddf46b233b8a08988c 2 parents 98bef28 + 0dc2bd7
@willdurand willdurand authored
View
24 Command/FixturesLoadCommand.php
@@ -163,9 +163,7 @@ protected function loadFixtures(InputInterface $input, OutputInterface $output,
return;
}
- $finder = new Finder();
- $tmpdir = $this->getApplication()->getKernel()->getRootDir() . '/cache/propel';
- $datas = $finder->name('*.' . $type)->in($this->absoluteFixturesPath);
+ $datas = $this->getFixtureFiles($type);
if (count(iterator_to_array($datas)) === 0) {
return -1;
@@ -210,9 +208,8 @@ protected function loadFixtures(InputInterface $input, OutputInterface $output,
*/
protected function loadSqlFixtures(InputInterface $input, OutputInterface $output)
{
- $finder = new Finder();
$tmpdir = $this->getApplication()->getKernel()->getRootDir() . '/cache/propel';
- $datas = $finder->name('*.sql')->in($this->absoluteFixturesPath);
+ $datas = $this->getFixtureFiles('sql');
$this->prepareCache($tmpdir);
@@ -286,4 +283,21 @@ protected function insertSql($config, $sqlDir, $schemaDir, $output)
return true;
}
+
+ /**
+ * Returns the fixtures files to load.
+ *
+ * @param string $type The extension of the files.
+ * @param string $in The directory in which we search the files. If null,
+ * we'll use the absoluteFixturesPath property.
+ *
+ * @return \Iterator An iterator through the files.
+ */
+ protected function getFixtureFiles($type = 'sql', $in = null)
+ {
+ $finder = new Finder();
+ $finder->sortByName()->name('*.' . $type);
+
+ return $finder->in(null !== $in ? $in : $this->absoluteFixturesPath);
+ }
}
View
14 DependencyInjection/PropelExtension.php
@@ -68,16 +68,14 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('converters.xml');
}
- if (0 === strncasecmp(PHP_SAPI, 'cli', 3)) {
- if (isset($config['build_properties']) && is_array($config['build_properties'])) {
- $buildProperties = $config['build_properties'];
- } else {
- $buildProperties = array();
- }
-
- $container->getDefinition('propel.build_properties')->setArguments(array($buildProperties));
+ if (isset($config['build_properties']) && is_array($config['build_properties'])) {
+ $buildProperties = $config['build_properties'];
+ } else {
+ $buildProperties = array();
}
+ $container->getDefinition('propel.build_properties')->setArguments(array($buildProperties));
+
if (!empty($config['dbal'])) {
$this->dbalLoad($config['dbal'], $container);
}
View
13 Resources/views/Collector/propel.html.twig
@@ -29,6 +29,17 @@
<style type="text/css">
.SQLKeyword {
color: blue;
+ white-space: nowrap;
+ }
+ .SQLName {
+ color: #464646;
+ white-space: nowrap;
+ }
+ .SQLInfo, .SQLComment {
+ color: gray;
+ display: block;
+ font-size: 0.9em;
+ margin: 3px 0;
}
</style>
@@ -47,7 +58,7 @@
<tr>
<td>
<code>{{ query.sql|format_sql }}</code>
- <div style="color: gray;font-size: 0.9em;">Time: {{ query.time }} - Memory: {{ query.memory }}</div>
+ <div class="SQLInfo">Time: {{ query.time }} - Memory: {{ query.memory }}</div>
</td>
</tr>
{% endfor %}
View
77 Tests/FixturesLoadCommandTest.php
@@ -0,0 +1,77 @@
+<?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 Tests\Command;
+
+use Symfony\Component\Filesystem\Filesystem;
+
+use Propel\PropelBundle\Tests\TestCase;
+use Propel\PropelBundle\Command\FixturesLoadCommand;
+
+/**
+ * @author Kévin Gomez <contact@kevingomez.fr>
+ */
+class FixturesLoadCommandTest extends TestCase
+{
+ protected $command;
+
+ public function setUp()
+ {
+ $this->command = new TestableFixturesLoadCommand('testable-command');
+
+ // let's create some dummy fixture files
+ $this->fixtures_dir = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'propel';
+ $this->fixtures_files = array(
+ '10_foo.yml', '20_bar.yml', '15_biz.yml', '18_boo.sql', '42_baz.sql'
+ );
+
+ $this->filesystem = new Filesystem();
+ $this->filesystem->mkdir($this->fixtures_dir);
+ foreach ($this->fixtures_files as $file)
+ {
+ $this->filesystem->touch($this->fixtures_dir . DIRECTORY_SEPARATOR . $file);
+ }
+ }
+
+ public function tearDown()
+ {
+ $this->filesystem->remove($this->fixtures_dir);
+ }
+
+ public function testOrderedFixturesFiles()
+ {
+ $this->assertEquals(
+ array('10_foo.yml', '15_biz.yml', '20_bar.yml',),
+ $this->cleanFixtureIterator($this->command->getFixtureFiles('yml', $this->fixtures_dir))
+ );
+
+ $this->assertEquals(
+ array('18_boo.sql', '42_baz.sql',),
+ $this->cleanFixtureIterator($this->command->getFixtureFiles('sql', $this->fixtures_dir))
+ );
+ }
+
+ protected function cleanFixtureIterator($file_iterator)
+ {
+ $tmp_dir = $this->fixtures_dir;
+
+ return array_map(function($file) use($tmp_dir) {
+ return str_replace($tmp_dir . DIRECTORY_SEPARATOR, '', $file);
+ }, array_keys(iterator_to_array($file_iterator)));
+ }
+}
+
+class TestableFixturesLoadCommand extends FixturesLoadCommand
+{
+ public function getFixtureFiles($type = 'sql', $in = null)
+ {
+ return parent::getFixtureFiles($type, $in);
+ }
+}
View
3  Tests/autoload.php.dist
@@ -10,6 +10,9 @@ $loader->registerNamespaces(array(
'Symfony' => array($vendorDir.'/symfony/src'),
'Sensio\\Bundle\\FrameworkExtraBundle' => array($vendorDir),
));
+$loader->registerPrefixes(array(
+ 'Twig_' => $vendorDir.'/symfony/vendor/twig/lib',
+));
$loader->register();
set_include_path(get_include_path() . PATH_SEPARATOR . $vendorDir.'/phing/classes');
View
57 Twig/Extension/SyntaxExtension.php
@@ -33,9 +33,62 @@ public function getName()
public function formatSQL($sql)
{
- $sql = preg_replace('/\b(UPDATE|SET|SELECT|FROM|AS|LIMIT|ASC|COUNT|DESC|WHERE|LEFT JOIN|INNER JOIN|RIGHT JOIN|ORDER BY|GROUP BY|IN|LIKE|DISTINCT|DELETE|INSERT|INTO|VALUES|ON|AND|OR)\b/', '<span class="SQLKeyword">\\1</span>', $sql);
+ // list of keywords to prepend a newline in output
+ $newlines = array(
+ 'FROM',
+ '(((FULL|LEFT|RIGHT)? ?(OUTER|INNER)?|CROSS|NATURAL)? JOIN)',
+ 'VALUES',
+ 'WHERE',
+ 'ORDER BY',
+ 'GROUP BY',
+ 'HAVING',
+ 'LIMIT',
+ );
+
+ // list of keywords to highlight
+ $keywords = array_merge($newlines, array(
+ // base
+ 'SELECT', 'UPDATE', 'DELETE', 'INSERT', 'REPLACE',
+ 'SET',
+ 'INTO',
+ 'AS',
+ 'DISTINCT',
+
+ // most used methods
+ 'COUNT',
+ 'AVG',
+ 'MIN',
+ 'MAX',
+
+ // joins
+ 'ON', 'USING',
+
+ // where clause
+ '(IS (NOT)?)?NULL',
+ '(NOT )?IN',
+ '(NOT )?I?LIKE',
+ 'AND', 'OR', 'XOR',
+ 'BETWEEN',
+
+ // order, group, limit ..
+ 'ASC',
+ 'DESC',
+ 'OFFSET',
+ ));
- $sql = preg_replace('/\b(FROM|WHERE|INNER JOIN|LEFT JOIN|RIGHT JOIN|ORDER BY|GROUP BY)\b/', '<br />\\1', $sql);
+ $sql = preg_replace(array(
+ '/\b('.implode('|', $newlines).')\b/',
+ '/\b('.implode('|', $keywords).')\b/',
+ '/(\/\*.*\*\/)/',
+ '/(`[^`.]*`)/',
+ '/(([0-9a-zA-Z$_]+)\.([0-9a-zA-Z$_]+))/',
+ ), array(
+ '<br />\\1',
+ '<span class="SQLKeyword">\\1</span>',
+ '<span class="SQLComment">\\1</span>',
+ '<span class="SQLName">\\1</span>',
+ '<span class="SQLName">\\1</span>',
+ ), $sql);
return $sql;
}
View
1  phpunit.xml.dist
@@ -22,6 +22,7 @@
<directory>./</directory>
<exclude>
<directory>./Tests</directory>
+ <directory>./vendor</directory>
</exclude>
</whitelist>
</filter>
View
2  vendor/install_vendors.php
@@ -23,3 +23,5 @@
system(sprintf('cd %s && git fetch -q origin && git reset --hard %s', escapeshellarg($installDir), escapeshellarg($rev)));
}
+
+system(sprintf('cd %s && php vendors.php', escapeshellarg($vendorDir.'/symfony')));
Please sign in to comment.
Something went wrong with that request. Please try again.