Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drupal coding standars #177

Merged
merged 37 commits into from
Aug 17, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
3bb56f1
update travis file
dmouse Jul 14, 2014
d039b0d
update composer.json
dmouse Jul 14, 2014
57f90e6
setUp temporal directory
dmouse Jul 14, 2014
d14ed5d
update Module generator test
dmouse Jul 14, 2014
97975cf
update plugin block generator test
dmouse Jul 14, 2014
6a70834
change dir module
dmouse Jul 14, 2014
936735f
drupal standars
dmouse Jul 14, 2014
6268174
update doc block
dmouse Jul 14, 2014
749a847
remove symfony config component
dmouse Jul 15, 2014
397aa51
rever 936735f and 6268174 commits
dmouse Jul 15, 2014
bbafbc0
remove unused class
dmouse Jul 27, 2014
d7b699e
adding psr-4 autoload
dmouse Jul 27, 2014
7323017
generator test
dmouse Jul 27, 2014
4c1f2a5
remove tmp directory
dmouse Jul 27, 2014
ff61d00
Merge remote-tracking branch 'upstream/master' into drupal-standars
dmouse Jul 27, 2014
cd0b931
get module path method
dmouse Jul 27, 2014
1abacbb
generator controller class
dmouse Jul 27, 2014
205f01f
Merge branch 'drupal-standars' of github.com:dmouse/DrupalAppConsole …
dmouse Aug 3, 2014
cc2dd97
update autoload for phpunit
dmouse Aug 3, 2014
1432e5b
exit 1 if get error in coding standars
dmouse Aug 3, 2014
480fa7a
reorder in task
dmouse Aug 3, 2014
dade173
show message error
dmouse Aug 3, 2014
36eb22f
change doc block
dmouse Aug 3, 2014
8751e11
added space
dmouse Aug 17, 2014
d3a9b99
added spaces
dmouse Aug 17, 2014
a3b3071
change braces to same line
dmouse Aug 17, 2014
77576a0
remove space
dmouse Aug 17, 2014
3a07a85
change braces to same line
dmouse Aug 17, 2014
fe297d3
doc block added
dmouse Aug 17, 2014
94dd432
public declaration
dmouse Aug 17, 2014
1d3f95b
change braces to same line
dmouse Aug 17, 2014
90ad74a
change braces to same line
dmouse Aug 17, 2014
f23c0bc
change braces to same line
dmouse Aug 17, 2014
8bab158
change braces to same line
dmouse Aug 17, 2014
56527c8
change braces to same line
dmouse Aug 17, 2014
6b44d0a
comment check sniffer
dmouse Aug 17, 2014
3fd736f
change drupal version
dmouse Aug 17, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ php:
- 5.6

before_script:
- composer install
- composer install --dev --prefer-source

after_success:
- ./bin/phpcs --standard=vendor/drupal/coder/coder_sniffer/Drupal/ruleset.xml /tmp/modules/*
#- if ./bin/phpcs --standard=vendor/drupal/coder/coder_sniffer/Drupal/ruleset.xml /tmp/modules/* | egrep "FOUND ([1-9]+) ERRORS" --quiet; then echo "\nErrors in coding standards\n"; exit 1; fi
- rm -r /tmp/modules
65 changes: 65 additions & 0 deletions Tests/Generator/CommandGeneratorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

/**
* @file
* Contains \Drupal\AppConsole\Test\Generator\CommandGeneratorTest.
*/

namespace Drupal\AppConsole\Test\Generator;


use Drupal\AppConsole\Generator\CommandGenerator;

class CommandGeneratorTest extends GeneratorTest
{
/**
* @dataProvider commandData
*/
public function testCommandGenerator($parameters)
{
list($module, $command, $class_name, $container) = $parameters;

$generator = $this->getGenerator();

$dir_module = $this->dir . '/' . $module;

$generator->expects($this->once())
->method('getCommandPath')
->will(
$this->returnValue(
$dir_module . '/src/Command'
)
);

// Generate command
$generator->generate($module, $command, $class_name, $container);

$this->assertTrue(
is_file($dir_module . '/src/Command/' . $class_name . '.php'),
'Command class generated'
);
}

public function commandData()
{
return [
[
['command_' . rand(), 'command:default', 'CommandDefault', false]
],
[
['command_' . rand(), 'command:default', 'CommandDefault', true]
],
];
}

protected function getGenerator()
{
$generator = $this->getMockBuilder('\Drupal\AppConsole\Generator\CommandGenerator')
->setMethods(['getCommandPath'])
->getMock();

$generator->setSkeletonDirs($this->getSkeletonDirs());

return $generator;
}
}
99 changes: 99 additions & 0 deletions Tests/Generator/ControllerGeneratorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php
/**
* Created by PhpStorm.
* User: dmouse
* Date: 7/27/14
* Time: 2:50 PM
*/

namespace Drupal\AppConsole\Test\Generator;


class ControllerGeneratorTest extends GeneratorTest
{

/**
* @dataProvider commandData
*/
public function testGenerateController($parameters)
{
list($module, $class_name, $method_name, $route, $test, $services, $class_machine_name) = $parameters;

$generator = $this->getGenerator();

$generator->expects($this->once())
->method('getControllerPath')
->will(
$this->returnValue(
$this->getModulePath($module) . '/src/Controller'
)
);

$generator->expects($this->once())
->method('getModulePath')
->will(
$this->returnValue(
$this->getModulePath($module)
)
);

$generator->expects($this->any())
->method('getTestPath')
->will(
$this->returnValue(
$this->getModulePath($module) . '/Tests/Controller'
)
);

$generator->generate($module, $class_name, $method_name, $route, $test, $services, $class_machine_name);

$this->assertTrue(
is_file($this->getModulePath($module) . '/src/Controller/' . $class_name . '.php'),
'Generate controller class'
);

$this->assertTrue(
is_file($this->getModulePath($module) . '/' . $module . '.routing.yml'),
'Generate routing file'
);

if ($test) {
$this->assertTrue(
is_file($this->getModulePath($module) . '/Tests/Controller/' . $class_name . 'Test.php'),
'Generate test class'
);
}
}

public function commandData()
{
$services = [
'twig' => [
'name' => 'twig',
'machine_name' => 'twig',
'class' => 'Twig_Environment',
'short'=>'Twig_Environment',
]
];

return [
[
['controller_' . rand(), 'DefaultController', 'index', '/index', false, null, 'default_controller']
],
[
['controller_' . rand(), 'DefaultController', 'index', '/index', true, $services, 'default_controller']
],
];
}

protected function getGenerator()
{
$generator = $this->getMockBuilder('\Drupal\AppConsole\Generator\ControllerGenerator')
->setMethods(['getControllerPath', 'getModulePath', 'getTestPath'])
->getMock();

$generator->setSkeletonDirs($this->getSkeletonDirs());

return $generator;
}
}
19 changes: 7 additions & 12 deletions Tests/Generator/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

namespace Drupal\AppConsole\Test\Generator;

use Symfony\Component\Filesystem\Filesystem;

abstract class GeneratorTest extends \PHPUnit_Framework_TestCase
{
var $dir;
Expand All @@ -19,15 +17,7 @@ public function setUp()

public function setUpTemporalDirectory()
{
$this->dir = sys_get_temp_dir() . "/module";

$this->filesystem = new Filesystem();
$this->filesystem->remove($this->dir);
}

public function tearDown()
{
$this->filesystem->remove($this->dir);
$this->dir = sys_get_temp_dir() . "/modules";
}

public function getSkeletonDirs()
Expand All @@ -38,4 +28,9 @@ public function getSkeletonDirs()

return $skeletonDirs;
}
}

public function getModulePath($module)
{
return $this->dir . '/' . $module;
}
}
54 changes: 27 additions & 27 deletions Tests/Generator/ModuleGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,77 +42,77 @@ public function testGenerateModule($parameters)
);

$files = [
'foo/foo.info.yml',
'foo/foo.module',
$machine_name . '.info.yml',
$machine_name . '.module',
];

foreach ($files as $file) {
$this->assertTrue(
file_exists($this->dir . '/' . $file),
sprintf('%s has been generated', $this->dir . '/' .$dir)
file_exists($dir . '/' . $machine_name . '/' . $file),
sprintf('%s has been generated', $dir . '/' . $machine_name . '/' . $file)
);
}

if ($controller) {
$this->assertTrue(
file_exists($this->dir . '/foo/src/Controller/DefaultController.php'),
file_exists($dir . '/' .$machine_name . '/src/Controller/DefaultController.php'),
sprintf('%s has been generated',
$this->dir . '/foo/src/Controller/DefaultController.php'
$dir . $machine_name . '/src/Controller/DefaultController.php'
)
);
$this->assertTrue(
file_exists($this->dir . '/foo/foo.routing.yml'),
file_exists($dir . '/' . $machine_name . "/$machine_name.routing.yml"),
sprintf('%s has been generated',
$this->dir . '/foo/foo.routing.yml'
$dir . '/' . $machine_name . "/$machine_name.routing.yml"
)
);

if ($tests) {
$this->assertTrue(
file_exists($this->dir . '/foo/Tests/Controller/DefaultControllerTest.php'),
file_exists($dir . '/' . $machine_name . '/Tests/Controller/DefaultControllerTest.php'),
sprintf('%s has been generated',
$this->dir . '/foo/Tests/Controller/DefaultControllerTest.php'
$dir . '/' . $machine_name . '/Tests/Controller/DefaultControllerTest.php'
)
);
}
}

$dirs = [
'foo',
'foo/src',
'foo/Tests',
'foo/templates',
'foo/src/Controller',
'foo/src/Form',
'foo/src/Plugin',
$folders = [
'',
'src',
'Tests',
'templates',
'src/Controller',
'src/Form',
'src/Plugin',
];

if ($structure) {
foreach ($dirs as $dir) {
foreach ($folders as $folder) {
$this->assertTrue(
is_dir($this->dir . '/' . $dir),
sprintf('%s has been generated', $this->dir . '/' .$dir)
is_dir($dir . '/' . $machine_name . '/' . $folder),
sprintf('%s has been generated', $dir . '/' . $machine_name . '/' . $folder)
);
}
}
}

public function commandData()
{
$this->dir = sys_get_temp_dir() . "/module";
$this->setUpTemporalDirectory();

return [
[
['Foo', 'foo', $this->dir, 'Description', '8.x', 'Other', true, true, true],
['Foo', 'foo' . rand(), $this->dir, 'Description', '8.x', 'Other', false, false, false],
],
[
['Foo', 'foo', $this->dir, 'Description', '8.x', 'Other', false, true, true],
['Foo', 'foo' . rand(), $this->dir, 'Description', '8.x', 'Other', false, true, true],
],
[
['Foo', 'foo', $this->dir, 'Description', '8.x', 'Other', false, false, true],
['Foo', 'foo' . rand(), $this->dir, 'Description', '8.x', 'Other', false, false, true],
],
[
['Foo', 'foo', $this->dir, 'Description', '8.x', 'Other', false, false, false],
['Foo', 'foo' . rand(), $this->dir, 'Description', '8.x', 'Other', true, true, true],
],
];
}
Expand All @@ -123,4 +123,4 @@ protected function getGenerator()
$generator->setSkeletonDirs(__DIR__.'/../../src/Resources/skeleton');
return $generator;
}
}
}
34 changes: 22 additions & 12 deletions Tests/Generator/PluginBlockGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,26 @@ public function testGeneratePluginBlock($parameters)
{
$this->setUpTemporalDirectory();

// Get parameters
list($module, $class_name, $plugin_label, $plugin_id, $services, $inputs) = $parameters;
$this->getGenerator()->generate($module, $class_name, $plugin_label, $plugin_id, $services, $inputs);

// Get generator
$generator = $this->getGenerator();

$dir_module = $this->dir . '/' . $module;
// Set plugin path.
$generator->expects($this->once())
->method('getPluginPath')
->will($this->returnValue(
$dir_module . '/src/Plugin/Block')
);

// Generate plugin block
$generator->generate($module, $class_name, $plugin_label, $plugin_id, $services, $inputs);

$this->assertTrue(
file_exists($this->dir . '/src/Plugin/Block/' . $class_name .'.php'),
sprintf('%s has been generated', $this->dir . '/src/Plugin/Block/'.$class_name.'.php')
file_exists($dir_module . '/src/Plugin/Block/' . $class_name .'.php'),
sprintf('%s has been generated', $dir_module . '/src/Plugin/Block/'.$class_name.'.php')
);

$contains = [
Expand Down Expand Up @@ -51,7 +65,7 @@ public function testGeneratePluginBlock($parameters)
];
}

$content = file_get_contents($this->dir . '/src/Plugin/Block/' . $class_name .'.php');
$content = file_get_contents($dir_module . '/src/Plugin/Block/' . $class_name .'.php');
foreach ($contains as $contain) {
$this->assertContains($contain, $content);
}
Expand All @@ -78,16 +92,16 @@ public function commandData()

return [
[
['foo', 'FooBlock', 'Foo Block', 'foo_block', null, []]
['plugin_block' . rand(), 'FooBlock', 'Foo Block', 'foo_block', null, []]
],
[
['foo', 'FooBlock', 'Foo Block', 'foo_block', $services, []]
['plugin_block' . rand(), 'FooBlock', 'Foo Block', 'foo_block', $services, []]
],
[
['foo', 'FooBlock', 'Foo Block', 'foo_block', null, $inputs]
['plugin_block' . rand(), 'FooBlock', 'Foo Block', 'foo_block', null, $inputs]
],
[
['foo', 'FooBlock', 'Foo Block', 'foo_block', $services, $inputs]
['plugin_block' . rand(), 'FooBlock', 'Foo Block', 'foo_block', $services, $inputs]
],
];
}
Expand All @@ -100,10 +114,6 @@ protected function getGenerator()

$generator->setSkeletonDirs($this->getSkeletonDirs());

$generator->expects($this->once())
->method('getPluginPath')
->will($this->returnValue($this->dir . '/src/Plugin/Block'));

return $generator;
}
}
Loading