CakePHP2계의 환경 구축
환경
$ php --version
PHP 7.2.10-0ubuntu1 (cli) (built: Sep 13 2018 13:38:55) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.2.10-0ubuntu1, Copyright (c) 1999-2018, by Zend Technologies
$ composer --version
Composer version 1.8.0 2018-12-03 10:31:16
OS는 Ubuntu에서 포크 된 Pop!_OS라는 OS입니다.
$ cat /etc/os-release
NAME="Pop!_OS"
VERSION="18.10"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Pop!_OS 18.10"
VERSION_ID="18.10"
HOME_URL="https://system76.com/pop"
SUPPORT_URL="http://support.system76.com"
BUG_REPORT_URL="https://github.com/pop-os/pop/issues"
PRIVACY_POLICY_URL="https://system76.com/privacy"
VERSION_CODENAME=cosmic
UBUNTU_CODENAME=cosmic
CakePHP2.x 설치
간단히 말하면
composer.json
를 만들고 composer install
하면 로컬에 cakephp가 설치되어 사용할 수 있게 됩니다.다음은 composer.json입니다.
{
"name": "otameshi",
"repositories": [
{
"type": "pear",
"url": "http://pear.cakephp.org"
}
],
"require": {
"cakephp/cakephp": ">=2.4.9"
},
"config": {
"vendor-dir": "Vendor/"
}
}
그러나 이것으로
composer install
그러면 다음과 같은 오류가 발생합니다.$ composer install
Loading composer repositories with package information
Initializing PEAR repository http://pear.cakephp.org
PHP Fatal error: Uncaught Error: Call to undefined function Composer\Repository\Pear\simplexml_load_string() in phar:///usr/local/bin/composer/src/Composer/Repository/Pear/BaseChannelReader.php:74
구그하면 xml 주위의 라이브러리가 부족한 것 같기 때문에 인스톨합니다.
$ sudo apt install php7.2-xml
이것을 넣으면
composer install
가 지나갔습니다.$ composer install
Loading composer repositories with package information
Initializing PEAR repository http://pear.cakephp.org
PEAR repository from http://pear.cakephp.org could not be loaded. Your configuration does not allow connections to http://pear.cakephp.org/channel.xml. Seehttps://getcomposer.org/doc/06-config.md#secure-http for details.
Updating dependencies (including require-dev)
Package operations: 1 install, 0 updates, 0 removals
- Installing cakephp/cakephp (2.10.14): Downloading (100%)
cakephp/cakephp suggests installing ext-mcrypt (You need to install ext-openssl or ext-mcrypt to use AES-256 encryption)
Writing lock file
Generating autoload files
$ la
total 20KT --
drwxrwxr-x 3 asmsuechan asmsuechan 4.0K 1月 17 10:04 ./
drwxr-xr-x 5 asmsuechan asmsuechan 4.0K 1月 16 14:11 ../
drwxrwxr-x 5 asmsuechan asmsuechan 4.0K 1月 17 10:04 Vendor/
-rw-rw-r-- 1 asmsuechan asmsuechan 265 1月 16 13:37 composer.json
-rw-rw-r-- 1 asmsuechan asmsuechan 2.3K 1月 17 10:04 composer.lock
bake 명령
./Vendor/bin/cake bake
를 실행하면 파일을 잘 만들 수 있습니다.la myapp
total 64K
drwxr-xr-x 14 asmsuechan asmsuechan 4.0K 1月 17 10:26 ./
drwxrwxr-x 4 asmsuechan asmsuechan 4.0K 1月 17 10:26 ../
-rwxr-xr-x 1 asmsuechan asmsuechan 116 12月 20 10:45 .htaccess*
drwxr-xr-x 3 asmsuechan asmsuechan 4.0K 1月 17 10:27 Config/
drwxr-xr-x 4 asmsuechan asmsuechan 4.0K 1月 17 10:26 Console/
drwxr-xr-x 3 asmsuechan asmsuechan 4.0K 1月 17 10:26 Controller/
drwxr-xr-x 2 asmsuechan asmsuechan 4.0K 1月 17 10:26 Lib/
drwxr-xr-x 3 asmsuechan asmsuechan 4.0K 1月 17 10:26 Locale/
drwxr-xr-x 4 asmsuechan asmsuechan 4.0K 1月 17 10:26 Model/
drwxr-xr-x 2 asmsuechan asmsuechan 4.0K 1月 17 10:26 Plugin/
drwxr-xr-x 4 asmsuechan asmsuechan 4.0K 1月 17 10:26 Test/
drwxr-xr-x 2 asmsuechan asmsuechan 4.0K 1月 17 10:26 Vendor/
drwxr-xr-x 9 asmsuechan asmsuechan 4.0K 1月 17 10:26 View/
-rwxr-xr-x 1 asmsuechan asmsuechan 194 12月 20 10:45 index.php*
drwxrwxrwx 6 asmsuechan asmsuechan 4.0K 1月 17 10:26 tmp/
drwxr-xr-x 6 asmsuechan asmsuechan 4.0K 1月 17 10:26 webroot/
잘 했어요.
PHPUnit 설치
./Console/cake test
실행하면 PHPUnit을 설치하라는 메시지가 나타납니다. 정중하게 버전 지정으로.Error: Please install PHPUnit framework v3.7 (http://www.phpunit.de)
#0 /home/asmsuechan/src/asmsuechan/otameshi/Vendor/cakephp/cakephp/lib/Cake/Console/ShellDispatcher.php(218): TestShell->initialize()
#1 /home/asmsuechan/src/asmsuechan/otameshi/Vendor/cakephp/cakephp/lib/Cake/Console/ShellDispatcher.php(66): ShellDispatcher->dispatch()
#2 /home/asmsuechan/src/asmsuechan/otameshi/myapp/Console/cake.php(48): ShellDispatcher::run(Array)
#3 {main}
composer require
명령으로 설치합니다.$ composer require --dev phpunit/phpunit ^3.7
Initializing PEAR repository http://pear.cakephp.org
PEAR repository from http://pear.cakephp.org could not be loaded. Your configuration does not allow connections to http://pear.cakephp.org/channel.xml. Seehttps://getcomposer.org/doc/06-config.md#secure-http for details.
./composer.json has been updated
Loading composer repositories with package information
Initializing PEAR repository http://pear.cakephp.org
PEAR repository from http://pear.cakephp.org could not be loaded. Your configuration does not allow connections to http://pear.cakephp.org/channel.xml. Seehttps://getcomposer.org/doc/06-config.md#secure-http for details.
Updating dependencies (including require-dev)
Package operations: 9 installs, 0 updates, 0 removals
- Installing symfony/polyfill-ctype (v1.10.0): Downloading (100%)
- Installing symfony/yaml (v2.8.49): Downloading (100%)
- Installing phpunit/php-text-template (1.2.1): Downloading (100%)
- Installing phpunit/phpunit-mock-objects (1.2.3): Downloading (100%)
- Installing phpunit/php-timer (1.0.9): Downloading (100%)
- Installing phpunit/php-file-iterator (1.4.5): Downloading (100%)
- Installing phpunit/php-token-stream (1.2.2): Downloading (100%)
- Installing phpunit/php-code-coverage (1.2.18): Downloading (100%)
- Installing phpunit/phpunit (3.7.38): Downloading (100%)
phpunit/phpunit-mock-objects suggests installing ext-soap (*)
phpunit/php-code-coverage suggests installing ext-xdebug (>=2.0.5)
phpunit/phpunit suggests installing phpunit/php-invoker (~1.1)
Writing lock file
Generating autoload files
테스트 실행
phpunit을 설치했으므로 실제로 간단한 구성 요소와 그 테스트를 작성해 보겠습니다.
// myapp/Controller/Component/CalculateComponent.php
<?php
class CalculateComponent {
function add ($x, $y) {
return $x + $y;
}
}
// myapp/Test/Case/Controller/Component/CalculateComponentTest.php
<?php
App::uses('CalculateComponent', 'Controller/Component');
class CalculateComponentTest extends CakeTestCase {
private $CalculateComponent = null;
public function setUp() {
$this->CalculateComponent = new CalculateComponent;
parent::setUp();
}
function testAdd() {
$result = $this->CalculateComponent->add(1,2);
$this->assertTrue($result == 3);
}
}
실제로 테스트를 움직여 보겠습니다.
$ ./Console/cake test app
Welcome to CakePHP v2.10.14 Console
---------------------------------------------------------------
App : myapp
Path: /home/asmsuechan/src/asmsuechan/otameshi/myapp/
---------------------------------------------------------------
CakePHP Test Shell
---------------------------------------------------------------
App Test Cases:
[1] AllTests
[2] Controller/Component/CalculateComponent
What test case would you like to run?
[q] > 2
PHPUnit 3.7.38 by Sebastian Bergmann.
The Xdebug extension is not loaded. No code coverage will be generated.
PHPUnit 3.7.38 by Sebastian Bergmann.
Configuration read from /home/asmsuechan/src/asmsuechan/otameshi/myapp/phpunit.xml
.
Time: 1 second, Memory: 6.00MB
OK (1 test, 1 assertion)
서버 시작
cake server
에서 서버가 시작됩니다.$ sudo ./Console/cake server
[sudo] password for asmsuechan:
Welcome to CakePHP v2.10.14 Console
---------------------------------------------------------------
App : myapp
Path: /home/asmsuechan/src/asmsuechan/otameshi/myapp/
DocumentRoot: /home/asmsuechan/src/asmsuechan/otameshi/myapp/webroot
---------------------------------------------------------------
built-in server is running in http://localhost/
[Thu Jan 17 11:36:26 2019] ::1:46716 [200]: /css/cake.generic.css
[Thu Jan 17 11:36:26 2019] ::1:46718 [200]: /img/cake.power.gif
[Thu Jan 17 11:36:26 2019] ::1:46720 [200]: /img/cake.icon.png
localohost에 액세스하면 이런 화면이 보입니다.
요약
오래된 환경을 구축하는 데 어려움. Docker로 바삭바삭할 수 있는 파워가 필요.
Reference
이 문제에 관하여(CakePHP2계의 환경 구축), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/asmsuechan/items/b17eb4585d4c9a823072텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)