Skip to content

Commit

Permalink
Merge pull request #1326 from phalcon/feature/#1324-working-with-tests
Browse files Browse the repository at this point in the history
#1324 - Working with tests
  • Loading branch information
Jeckerson authored Oct 14, 2019
2 parents d94c86b + 31ad848 commit 6cc68f5
Show file tree
Hide file tree
Showing 67 changed files with 188 additions and 840 deletions.
34 changes: 34 additions & 0 deletions .ci/install-phalcon.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env bash
#
# This file is part of the Phalcon Framework.
#
# (c) Phalcon Team <[email protected]>
#
# For the full copyright and license information, please view the
# LICENSE.txt file that was distributed with this source code.

set -e

: "${PHALCON_VERSION:=master}"

EXT_DIR="$(php-config --extension-dir)"
LOCAL_PATH="phalcon-$PHALCON_VERSION/php-$(php-config --vernum)/$TRAVIS_ARCH"

# Using cache only for tagged Phalcon versions
if [ "$PHALCON_VERSION" != "master" ] &&
[ "$PHALCON_VERSION" != "4.0.x" ] &&
[ -f "$HOME/assets/$LOCAL_PATH/phalcon.so" ]
then
cp "$HOME/assets/$LOCAL_PATH/phalcon.so" "$EXT_DIR/phalcon.so"
else
git clone --depth=1 -v https://github.com/phalcon/cphalcon.git -b "$PHALCON_VERSION" /tmp/phalcon
cd /tmp/phalcon/build || extit 1
./install --phpize "$(phpenv which phpize)" --php-config "$(phpenv which php-config)" 1> /dev/null

mkdir -p "$HOME/assets/$LOCAL_PATH"
cp "$EXT_DIR/phalcon.so" "$HOME/assets/$LOCAL_PATH/phalcon.so"
fi

echo extension=phalcon.so >> "$(phpenv prefix)/etc/php.ini"

"$(phpenv which php)" -m | grep -q phalcon
44 changes: 13 additions & 31 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
language: php

sudo: required
dist: trusty

php:
- 5.5
- 5.6

services:
- postgresql
- mysql

matrix:
include:
- php: 7.0
env: ZEND_BACKEND="--backend=ZendEngine3"
- php: 7.1
env: ZEND_BACKEND="--backend=ZendEngine3"
- php: 7.2
env: ZEND_BACKEND="--backend=ZendEngine3"
- php: 7.3
env: ZEND_BACKEND="--backend=ZendEngine3"

git:
depth: 1

cache:
apt: true
ccache: true
timeout: 691200
timeout: 604800
directories:
- .temp
- vendor
Expand All @@ -38,7 +29,7 @@ env:
global:
- PATH="$PATH:~/bin"
- DISPLAY=":99.0"
- PHALCON_VERSION="v3.4.0"
- PHALCON_VERSION=v4.0.0-rc.1

before_install:
- export PHP_VERSION=$(php-config --version)
Expand All @@ -48,38 +39,29 @@ before_install:
- export $(cut -d= -f1 $TRAVIS_BUILD_DIR/tests/_ci/environment)
- phpenv config-rm xdebug.ini || true
- if [ -n "$GH_TOKEN" ]; then composer config github-oauth.github.com $GH_TOKEN; fi;
- if [ ! -f "$HOME/cphalcon/$PHALCON_VERSION/tests/_ci/phalcon.ini" ]; then git clone -q --depth=1 https://github.com/phalcon/cphalcon.git $HOME/cphalcon/$PHALCON_VERSION >/dev/null 2>&1; fi;
- bash tests/_ci/setup_dbs.sh

install:
- if [ ! -f $HOME/ext/$PHALCON_VERSION/$PHP_VERSION/phalcon.so ]; then cd $HOME/cphalcon/$PHALCON_VERSION/build && bash ./install --phpize $(phpenv which phpize) --php-config $(phpenv which php-config) && mkdir -p $HOME/ext/$PHP_VERSION && cp $PHP_EXTENSION_DIR/phalcon.so $HOME/ext/$PHP_VERSION/phalcon.so; fi;
- if [ -f $HOME/ext/$PHALCON_VERSION/$PHP_VERSION/phalcon.so ]; then cp $HOME/ext/$PHALCON_VERSION/$PHP_VERSION/phalcon.so $PHP_EXTENSION_DIR/phalcon.so; fi;
- phpenv config-add $HOME/cphalcon/$PHALCON_VERSION/tests/_ci/phalcon.ini
- cd $TRAVIS_BUILD_DIR
- travis_retry composer install --prefer-dist --no-interaction
- if [ "$PHP_MAJOR" == "7" ]; then composer require --dev phpstan/phpstan:^0.9; fi;
- pecl install --force psr
- .ci/install-phalcon.sh

before_script:
- ln -s $PWD/phalcon.php ~/bin/phalcon
- travis_retry composer install --no-interaction --no-ansi --no-progress --no-suggest
- composer require --dev phpstan/phpstan
- ln -s $PWD/phalcon ~/bin/phalcon

script:
- mkdir .phalcon
- vendor/bin/phpcs
- vendor/bin/codecept build
- vendor/bin/codecept run unit -v
- vendor/bin/codecept run functional -v
- vendor/bin/codecept run console -v
- '[[ "$PHP_MAJOR" == "5" ]] || vendor/bin/phpstan analyse -l 5 -c phpstan.neon scripts -v'
# - vendor/bin/phpstan analyse -l 5 -c phpstan.neon scripts -v

notifications:
email:
recipients:
- build@phalconphp.com
- build@phalcon.io
on_success: change
on_failure: always

addons:
apt:
packages:
- mysql-server-5.6
- mysql-client-core-5.6
- mysql-client-5.6
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,19 @@ cd phalcon-devtools
```

This method requires a little bit more of setup. Probably the best way would be to symlink
the `phalcon.php` to a directory in your `PATH`, so you can issue phalcon commands in each directory
the `phalcon` file to a directory in your `PATH`, so you can issue phalcon commands in each directory
where a phalcon project resides.

```bash
cd phalcon-devtools
ln -s $(pwd)/phalcon.php /usr/bin/phalcon
ln -s $(pwd)/phalcon /usr/bin/phalcon
chmod ugo+x /usr/bin/phalcon
```

If you get a `"phalcon: command not found"` message while creating the symlink, make an alias.

```bash
alias phalcon=/home/[USERNAME]/phalcon-devtools/phalcon.php
alias phalcon=/home/[USERNAME]/phalcon-devtools/phalcon
```

## Usage
Expand Down
2 changes: 1 addition & 1 deletion box.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"main": "phalcon.php",
"main": "phalcon",
"output": "phalcon.phar",
"chmod": "0755",
"directories": [
Expand Down
5 changes: 1 addition & 4 deletions codeception.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ paths:
data: tests/_data
support: tests/_support
envs: tests/_envs
bootstrap: _bootstrap.php
settings:
# name of bootstrap that will be used
# each bootstrap file should be
# inside a suite directory.
bootstrap: _bootstrap.php
colors: true
# Tests (especially functional) can take a lot of memory
# We set a high limit for them by default.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@
"tests/_support/helpers.php"
]
},
"bin": ["phalcon.php"]
"bin": ["phalcon"]
}
File renamed without changes.
4 changes: 2 additions & 2 deletions phalcon.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@echo off

set PTOOLSPATH=%~dp0
php %PTOOLSPATH%phalcon.php %*
php %PTOOLSPATH%phalcon.php %*
4 changes: 2 additions & 2 deletions phalcon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ check_install(){
if [ -z "$PTOOLSPATH" ]; then
printf "\n${YELLOW}Phalcon Developer Tools Installer${NC}"
printf "\n"
printf "\n${PURPLE}Make sure phalcon.sh is in the same dir as phalcon.php${NC}"
printf "\n${PURPLE}Make sure phalcon.sh is in the same dir as phalcon file${NC}"
printf "\n${PURPLE}and that you are running this with sudo or as root.${NC}"
printf "\n"
printf "\nInstalling Devtools..."
Expand Down Expand Up @@ -147,5 +147,5 @@ init

if check_install; then
devtools=${PTOOLSPATH%/}
php "$devtools/phalcon.php" $*
php "$devtools/phalcon" $*
fi
4 changes: 2 additions & 2 deletions scripts/Phalcon/Access/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@

namespace Phalcon\Access;

use Phalcon\Di\Injectable;
use Phalcon\Events\Event;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Mvc\User\Component;

/**
* \Phalcon\Access\Manager
*
* @package Phalcon\Access
*/
class Manager extends Component
class Manager extends Injectable
{
const EXCEPTION_ACTION_DISALLOWED = 10;

Expand Down
6 changes: 3 additions & 3 deletions scripts/Phalcon/Builder/AllModels.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function __construct(array $options = [])

public function build()
{
if ($this->options->contains('directory')) {
if ($this->options->offsetExists('directory')) {
$this->path->setRootPath($this->options->get('directory'));
}

Expand Down Expand Up @@ -112,7 +112,7 @@ public function build()
*/
$db = new $adapterName($configArray);

if ($this->options->contains('schema')) {
if ($this->options->has('schema')) {
$schema = $this->options->get('schema');
} else {
$schema = Utils::resolveDbSchema($config->database);
Expand Down Expand Up @@ -175,7 +175,7 @@ public function build()
}

foreach ($db->listTables($schema) as $name) {
$className = ($this->options->contains('abstract') ? 'Abstract' : '');
$className = ($this->options->has('abstract') ? 'Abstract' : '');
$className .= Utils::camelize($name);

if (!file_exists($modelPath . $className . '.php') || $forceProcess) {
Expand Down
5 changes: 3 additions & 2 deletions scripts/Phalcon/Builder/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

namespace Phalcon\Builder;

use Phalcon\Config;
use Phalcon\Validation;
use Phalcon\Script\Color;
use Phalcon\Validation\Validator\Namespaces;
Expand All @@ -36,7 +37,7 @@ abstract class Component
{
/**
* Builder Options
* @var Options
* @var Config
*/
protected $options = null;

Expand All @@ -53,7 +54,7 @@ abstract class Component
*/
public function __construct(array $options = [])
{
$this->options = new Options($options);
$this->options = new Config($options);
$this->path = new Path(realpath('.') . DIRECTORY_SEPARATOR);
}

Expand Down
8 changes: 4 additions & 4 deletions scripts/Phalcon/Builder/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ public function __construct(array $options = [])
*/
public function build()
{
if ($this->options->contains('directory')) {
if ($this->options->has('directory')) {
$this->path->setRootPath($this->options->get('directory'));
}

$namespace = '';
if ($this->options->contains('namespace') && $this->checkNamespace($this->options->get('namespace'))) {
if ($this->options->has('namespace') && $this->checkNamespace($this->options->get('namespace'))) {
$namespace = 'namespace '.$this->options->get('namespace').';'.PHP_EOL.PHP_EOL;
}

Expand All @@ -78,7 +78,7 @@ public function build()
$controllersDir = $config->path('application.controllersDir');
}

if (!$this->options->contains('name')) {
if (!$this->options->has('name')) {
throw new BuilderException('The controller name is required.');
}

Expand All @@ -97,7 +97,7 @@ public function build()
$baseClass . "\n{\n\n\tpublic function indexAction()\n\t{\n\n\t}\n\n}\n\n";
$code = str_replace("\t", " ", $code);

if (file_exists($controllerPath) && !$this->options->contains('force')) {
if (file_exists($controllerPath) && !$this->options->has('force')) {
throw new BuilderException(sprintf('The Controller %s already exists.', $name));
}

Expand Down
12 changes: 4 additions & 8 deletions scripts/Phalcon/Builder/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@

namespace Phalcon\Builder;

use Phalcon\Db\Adapter\Pdo\AbstractPdo;
use Phalcon\Text;
use Phalcon\Utils;
use ReflectionClass;
use Phalcon\Db\Column;
use Phalcon\Validation;
use Phalcon\Db\Adapter\Pdo;
use Phalcon\Generator\Snippet;
use Phalcon\Db\ReferenceInterface;
use Phalcon\Exception\RuntimeException;
Expand Down Expand Up @@ -148,7 +148,7 @@ public function build()

$adapterName = 'Phalcon\Db\Adapter\Pdo\\' . $adapter;
unset($configArray['adapter']);
/** @var Pdo $db */
/** @var AbstractPdo $db */
$db = new $adapterName($configArray);

$initialize = [];
Expand Down Expand Up @@ -500,10 +500,6 @@ public function build()
$license = trim(file_get_contents('license.txt')) . PHP_EOL . PHP_EOL;
}

if (false == $alreadyGetSourced) {
$methodRawCode[] = $snippet->getModelSource($this->modelOptions->getOption('name'));
}

if (false == $alreadyFind) {
$methodRawCode[] = $snippet->getModelFind($this->modelOptions->getOption('className'));
}
Expand Down Expand Up @@ -624,10 +620,10 @@ protected function getEntityClassName(ReferenceInterface $reference, $namespace)
* Get reference list from option
*
* @param string $schema
* @param Pdo $db
* @param AbstractPdo $db
* @return array
*/
protected function getReferenceList($schema, Pdo $db)
protected function getReferenceList($schema, AbstractPdo $db)
{
if ($this->modelOptions->hasOption('referenceList')) {
return $this->modelOptions->getOption('referenceList');
Expand Down
4 changes: 2 additions & 2 deletions scripts/Phalcon/Builder/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function __construct(array $options)
*/
public function build()
{
if (!$this->options->contains('name')) {
if (!$this->options->has('name')) {
throw new BuilderException('Please, specify the model name');
}

Expand All @@ -74,7 +74,7 @@ public function build()
. 'templates' . DIRECTORY_SEPARATOR . 'module';
}

if ($this->options->contains('directory')) {
if ($this->options->has('directory')) {
$this->path->setRootPath($this->options->get('directory'));
}

Expand Down
Loading

0 comments on commit 6cc68f5

Please sign in to comment.