Skip to content

Commit

Permalink
Merge branch '4.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
markstory committed Jun 2, 2020
2 parents bc639ce + d832143 commit 1b41b03
Show file tree
Hide file tree
Showing 55 changed files with 1,194 additions and 3,416 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -1,5 +1,8 @@
/tmp/*
/vendor/*
/logs/*
/composer.lock
/plugins/DebugKit
/phpunit.phar
/phpcs.xml
.phpunit*
27 changes: 22 additions & 5 deletions .travis.yml
@@ -1,14 +1,31 @@
language: php

php:
- 5.6
- 7.0
- 7.2
- 7.3

sudo: false
env:
global:
- DEFAULT=1

before_script:
- composer install
matrix:
include:
- php: 7.2
env: PHPCS=1 DEFAULT=0

before_install:
- phpenv config-rm xdebug.ini

install:
- make install-dev

script:
- if [[ $DEFAULT == 1 ]]; then make test; fi
- if [[ $PHPCS == 1 ]]; then make check-cs; fi

cache:
directories:
- $HOME/.composer/cache

notifications:
email: false
15 changes: 15 additions & 0 deletions Makefile
@@ -0,0 +1,15 @@
.PHONY: install-dev test check-cs

DEV_DEPENDENCIES = cakephp/cakephp:^4.0 \
cakephp/cakephp-codesniffer:^4.0 \
mikey179/vfsstream:^1.6 \
phpunit/phpunit:^8.4

install-dev:
composer require --dev $(DEV_DEPENDENCIES)

test: install-dev
composer test

check-cs: install-dev
composer cs-check
98 changes: 32 additions & 66 deletions README.md
Expand Up @@ -2,93 +2,59 @@

[![Build Status](https://img.shields.io/travis/com/cakephp/upgrade?style=flat-square)](https://travis-ci.com/cakephp/upgrade)

Upgrade tools for CakePHP meant to facilitate migrating from CakePHP 2.x to 3.0.0.

**Warning** This tool is still under development and doesn't handle all aspects of migrating.
Upgrade tools for CakePHP meant to facilitate migrating from CakePHP 3.8+ to
4.0.0. This repository should be used as a standalone application and *not* as
a plugin.

## Installation

After downloading/cloning the upgrade tool, you need to install dependencies with `composer`
First clone this repository or download a zipball:

```bash
php composer.phar install
git clone git://github.com/cakephp/upgrade
```

Once dependencies are installed you can start using the `upgrade` shell.
Then to install dependencies with `composer`

```bash
php composer.phar install --no-dev
```

## Usage

The upgrade tool is intended to be run *before* you update your application's
dependencies to 4.0. The rector based tasks will not run correctly if your
application already has its dependencies updated to 4.x.

The upgrade tool provides a standalone application that can be used to upgrade
other applications or cakephp plugins. Each of the subcommands accepts a path
that points to the application you want to upgrade.

```bash
cd /path/to/upgrade
bin/cake upgrade all /home/mark/Sites/my-app
bin/cake upgrade skeleton /home/mark/Sites/my-app
```
The first command would run all the tasks at once on `/home/mark/Sites/my-app`,
which is probably the way most people will want to use it.
Additionally the second command would run the `skeleton` task on `/home/mark/Sites/my-app`.
This command is not included in `all` as it is only necessary for apps. Plugins don't need it.

It is recommended that you keep your application in version control, and keep
backups of it before using the upgrade tool.
# Run all upgrade tasks at once.
bin/cake upgrade /home/mark/Sites/my-app

### Order matters
# OR run upgrade tasks individually.
# Rename locale files
bin/cake upgrade file_rename locales /home/mark/Sites/my-app

Several of the commands have dependencies on each other and should be run in a specific order. It
is recommended that you run the following commands first before using other commands:
# Rename template files
bin/cake upgrade file_rename templates /home/mark/Sites/my-app

```bash
bin/cake upgrade locations [path]
bin/cake upgrade namespaces [path]
bin/cake upgrade app_uses [path]
# Run rector rules.
bin/cake upgrade rector /home/mark/Sites/my-app/src
bin/cake upgrade rector /home/mark/Sites/my-app/tests
bin/cake upgrade rector /home/mark/Sites/my-app/config
```

Once these three commands have been run, you can use the other commands in any order.
The `all` command already used the right order by default.

## Tasks Available

### locations
Move files/directories around. Run this *before* adding namespaces with the namespaces command.

### namespaces
Add namespaces to files based on their file path. Only run this *after* you have moved files.

### app_uses
Replace App::uses() with use statements

### rename_classes
Rename classes that have been moved/renamed. Run after replacing App::uses().

### rename_collections
Rename HelperCollection, ComponentCollection, and TaskCollection. Will also
rename component constructor arguments and \_Collection properties on all
objects.

### method_names
Updates the method names for a number of methods.

### method_signatures
Updates the method signatures for a number of methods.

### fixtures
Update fixtures to use new index/constraint features. This is necessary before running tests.

### tests
Update test cases regarding fixtures.

### i18n
Update translation functions regarding placeholders.

### skeleton
Add basic skeleton files and folders from the "app" repository.
## Development

### prefixed_templates
Move view templates for prefixed actions to prefix subfolder. eg. Users/admin_index.ctp becomes Admin/Users/index.ctp.
By default `admin` prefix is handled, you can run this task for other routing prefixes using `--prefix=other` as well.
To ease installation & usage, this package does not
use `require-dev` in `composer.json` as the installed PHPUnit and
CakePHP packages cause conflicts with the rector tasks.

## More Available Tasks
See [dereuromark/upgrade](https://github.com/dereuromark/upgrade) repo for a few more on-top tasks available, that have not been merged back into this main one yet.
To install dev-dependencies use `make install-dev`. Then you will be able to
run `vendor/bin/phpunit`. You can also use `make test` to install dependencies
and run tests.
16 changes: 8 additions & 8 deletions composer.json
@@ -1,16 +1,12 @@
{
"name": "cakephp/upgrade",
"description": "CakePHP upgrade tool",
"description": "Command line tool for updating CakePHP applications and plugins.",
"homepage": "http://cakephp.org",
"type": "project",
"license": "MIT",
"require": {
"cakephp/cakephp": "^3.7",
"cakephp/app": "^3.7",
"cakephp/plugin-installer": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7.14|^6.0"
"cakephp/console": "^4.0",
"rector/rector": "~0.6"
},
"autoload": {
"psr-4": {
Expand All @@ -19,7 +15,8 @@
},
"autoload-dev": {
"psr-4": {
"Cake\\Upgrade\\Test\\": "tests"
"Cake\\Upgrade\\Test\\": "tests",
"OldApp\\": "tests/OldApp"
}
},
"minimum-stability" : "dev",
Expand All @@ -28,6 +25,9 @@
"source": "https://github.com/cakephp/upgrade"
},
"scripts": {
"cs-check": "phpcs --colors --parallel=16 -p -s src/ tests/",
"cs-fix": "phpcbf --colors --parallel=16 -p src/ tests/",
"test": "phpunit",
"post-autoload-dump": "Cake\\Composer\\Installer\\PluginInstaller::postAutoloadDump"
}
}
19 changes: 0 additions & 19 deletions config/bootstrap.php
Expand Up @@ -22,18 +22,9 @@
* Bootstrap CakePHP.
*
* Does the various bits of setup that CakePHP needs to do.
* This includes:
*
* - Registering the CakePHP autoloader.
* - Setting the default application paths.
*/
require CORE_PATH . 'config' . DS . 'bootstrap.php';

use Cake\Cache\Cache;
use Cake\Console\ConsoleErrorHandler;
use Cake\Core\Configure;
use Cake\Core\Configure\Engine\PhpConfig;
use Cake\Error\ErrorHandler;
use Cake\Log\Log;

/**
Expand Down Expand Up @@ -75,14 +66,4 @@
*/
ini_set('intl.default_locale', Configure::read('App.defaultLocale'));

/*
* Register application error and exception handlers.
*/
$isCli = PHP_SAPI === 'cli';
if ($isCli) {
(new ConsoleErrorHandler(Configure::read('Error')))->register();
} else {
(new ErrorHandler(Configure::read('Error')))->register();
}

Log::setConfig(Configure::consume('Log'));
4 changes: 2 additions & 2 deletions config/requirements.php
Expand Up @@ -20,8 +20,8 @@
/*
* You can remove this if you are confident that your PHP version is sufficient.
*/
if (version_compare(PHP_VERSION, '5.6.0') < 0) {
trigger_error('Your PHP version must be equal or higher than 5.6.0 to use CakePHP.' . PHP_EOL, E_USER_ERROR);
if (version_compare(PHP_VERSION, '7.2.0') < 0) {
trigger_error('Your PHP version must be equal or higher than 7.2.0 to use CakePHP.' . PHP_EOL, E_USER_ERROR);
}

/*
Expand Down
20 changes: 20 additions & 0 deletions phpcs.xml.dist
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<ruleset name="CakePHP Upgrade">
<config name="installed_paths" value="../../cakephp/cakephp-codesniffer" />

<rule ref="CakePHP" />

<!--
Disable manually until rector is upgrade to nikic/php-parser 5.0
This is downgrading to cakephp-codesniffer 4.0.0-beta3 intead of 4.0
-->
<rule ref="PSR12.Files.FileHeader.SpacingAfterBlock">
<severity>0</severity>
</rule>
<rule ref="PSR12.Files.FileHeader.IncorrectOrder">
<severity>0</severity>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes.IncorrectWhitespaceAfterDeclare">
<severity>0</severity>
</rule>
</ruleset>
36 changes: 21 additions & 15 deletions src/Application.php
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

/**
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
Expand All @@ -14,38 +16,42 @@
*/
namespace Cake\Upgrade;

use Cake\Http\BaseApplication;
use Cake\Console\CommandCollection;
use Cake\Core\ConsoleApplicationInterface;
use Cake\Upgrade\Command\FileRenameCommand;
use Cake\Upgrade\Command\RectorCommand;
use Cake\Upgrade\Command\UpgradeCommand;

/**
* Application setup class.
*
* This defines the bootstrapping logic and middleware layers you
* want to use in your application.
*/
class Application extends BaseApplication
class Application implements ConsoleApplicationInterface
{

/**
* Setup the middleware queue your application will use.
* Load configuration data.
*
* @param \Cake\Http\MiddlewareQueue $middlewareQueue The middleware queue to setup.
* @return \Cake\Http\MiddlewareQueue The updated middleware queue.
* @return void
*/
public function middleware($middlewareQueue)
public function bootstrap(): void
{
return $middlewareQueue;
require_once dirname(__DIR__) . '/config/bootstrap.php';
}

/**
* Define the routes for an application.
* Define the console commands for an application.
*
* Use the provided RouteBuilder to define an application's routing.
*
* @param \Cake\Routing\RouteBuilder $routes A route builder to add routes into.
* @return void
* @param \Cake\Console\CommandCollection $commands The CommandCollection to add commands into.
* @return \Cake\Console\CommandCollection The updated collection.
*/
public function routes($routes)
public function console(CommandCollection $commands): CommandCollection
{
// Do not load routes.php
$commands->add('upgrade', UpgradeCommand::class);
$commands->add('upgrade file_rename', FileRenameCommand::class);
$commands->add('upgrade rector', RectorCommand::class);

return $commands;
}
}

0 comments on commit 1b41b03

Please sign in to comment.