Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Fix phpcs violation #30

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ language: php
sudo: false

php:
- 5.4
- 5.5
- 5.6
- 7.0

before_install:
- source tests/travis-github-pr-integration.sh
- if [ -f .git/shallow ]; then rm .git/shallow; fi
- composer install
- composer require --prefer-source --dev squizlabs/php_codesniffer:~2.0
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
],
"require": {
"codeception/codeception": "2.0.*"
"codeception/codeception": "2.1.*"
},
"autoload": {
"psr-4": {
Expand Down
23 changes: 20 additions & 3 deletions src/Command/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use Cake\Codeception\Lib\Generator\Helper;
use Cake\Shell\ServerShell;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -50,9 +51,24 @@ public function execute(InputInterface $input, OutputInterface $output)
"<fg=white;bg=magenta>Initializing Codeception in " . $realpath . "</fg=white;bg=magenta>\n"
);

if ($input->getOption('compat')) {
$compatibilitySetup = false;
try {
$compatibilitySetup = $input->getOption('compat');
} catch (InvalidArgumentException $e) {
$compatibilitySetup = false;
}


$customize = false;
try {
$customize = $input->getOption('customize');
} catch (InvalidArgumentException $e) {
$customize = false;
}

if ($compatibilitySetup) {
$this->compatibilitySetup($output);
} elseif ($input->getOption('customize')) {
} elseif ($customize) {
$this->customize($output);
} else {
$this->setup($output);
Expand Down Expand Up @@ -222,7 +238,8 @@ protected function createSuite($suite, $actor, $config)
chdir($root);
require $root . '/config/bootstrap.php';
EOF
);
);
@mkdir($this->helperDir);
file_put_contents(
$this->helperDir . DIRECTORY_SEPARATOR . $actor . 'Helper.php',
(new Helper($actor, $this->namespace))->produce()
Expand Down
5 changes: 2 additions & 3 deletions src/Command/Build.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ protected function buildActorsForConfig($configFile)
$file = $settings['path'].$this->getClassName($settings['class_name']).'.php';
$this->save($file, $contents, true);
$this->output->writeln(sprintf(
'%s.php generated succesfully, %s methods added',
$settings['class_name'],
$gen->getNumMethods()
'%s.php generated succesfully',
$settings['class_name']
));
}
}
Expand Down
40 changes: 35 additions & 5 deletions tests/Fixture/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,20 @@ public static function postInstall(Event $event)
$rootDir = dirname(dirname(__DIR__));

static::createAppConfig($rootDir, $io);
static::createWritableDirectories($rootDir, $io);

// ask if the permissions should be changed
if ($io->isInteractive()) {
$validator = (function ($arg) {
$validator = function ($arg) {
if (in_array($arg, ['Y', 'y', 'N', 'n'])) {
return $arg;
}
throw new Exception('This is not a valid answer. Please choose Y or n.');
});
};
$setFolderPermissions = $io->askAndValidate(
'<info>Set Folder Permissions ? (Default to Y)</info> [<comment>Y,n</comment>]? ',
$validator,
false,
10,
'Y'
);

Expand Down Expand Up @@ -85,6 +86,35 @@ public static function createAppConfig($dir, $io)
}
}

/**
* Create the `logs` and `tmp` directories.
*
* @param string $dir The application's root directory.
* @param \Composer\IO\IOInterface $io IO interface to write to console.
* @return void
*/
public static function createWritableDirectories($dir, $io)
{
$paths = [
'logs',
'tmp',
'tmp/cache',
'tmp/cache/models',
'tmp/cache/persistent',
'tmp/cache/views',
'tmp/sessions',
'tmp/tests'
];

foreach ($paths as $path) {
$path = $dir . '/' . $path;
if (!file_exists($path)) {
mkdir($path);
$io->write('Created `' . $path . '` directory');
}
}
}

/**
* Set globally writable permissions on the "tmp" and "logs" directory.
*
Expand All @@ -98,8 +128,8 @@ public static function setFolderPermissions($dir, $io)
{
// Change the permissions on a path and output the results.
$changePerms = function ($path, $perms, $io) {
// Get current permissions in decimal format so we can bitmask it.
$currentPerms = octdec(substr(sprintf('%o', fileperms($path)), -4));
// Get permission bits from stat(2) result.
$currentPerms = fileperms($path) & 0777;
if (($currentPerms & $perms) == $perms) {
return;
}
Expand Down
21 changes: 21 additions & 0 deletions tests/travis-github-pr-integration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

# Return if we are not in a Pull Request
[[ "$TRAVIS_PULL_REQUEST" = "false" ]] && return

GITHUB_PR_URL=https://api.github.com/repos/$TRAVIS_REPO_SLUG/pulls/$TRAVIS_PULL_REQUEST
GITHUB_PR_BODY=$(curl -s $GITHUB_PR_URL 2>/dev/null)

if [[ $GITHUB_PR_BODY =~ \"ref\":\ *\"([a-zA-Z0-9_-]*)\" ]]; then
export TRAVIS_PR_BRANCH=${BASH_REMATCH[1]}
else
return
fi

GITHUB_BRANCH_URL=https://api.github.com/repos/$TRAVIS_REPO_SLUG/branches/$TRAVIS_PR_BRANCH
if [ $(curl -s --head --request GET $GITHUB_BRANCH_URL | grep "200 OK" > /dev/null) ]; then
TRAVIS_BRANCH=$TRAVIS_PR_BRANCH
if [[ $GITHUB_PR_BODY =~ \"repo\":.*\"clone_url\":\ *\"https://github\.com/([a-zA-Z0-9_-]*/[a-zA-Z0-9_-]*)\.git.*\"base\" ]]; then
export TRAVIS_REPO_SLUG=${BASH_REMATCH[1]}
fi
fi