Slide 1

Slide 1 text

$BLF'FTU $POTJEFSBTNPPUI VQHSBEFUP$BLF1)1 https://www.lancers.jp/ Yuki Kanazawa

Slide 2

Slide 2 text

$BLF'FTU Speaker Biography 2 Yuki Kanzawa Lancers, Inc. / Site Reliability Engineer (2013/11 -) Live in Tokyo, Japan Github︓yKanazawa Twitter: @yakitori009 Language: C++, Java, PHP, Go Hobby: Shogi(Japanese Chess)

Slide 3

Slide 3 text

$BLF'FTU About Lancers https://www.lancers.jp/ Genre: Crowdsourcing Start: 2008/4 PHP 5.2 → 5.3 → 5.6 → 7.3 CakePHP 1.2 → 1.3 → 2.8 → 2.10

Slide 4

Slide 4 text

$BLF'FTU (PPHMF5SFOET PG1)1'SBNFXPSLT

Slide 5

Slide 5 text

$BLF'FTU Google Trends of PHP Framework TOP 5 Country (CakePHP) Japan Japan Finland South Africa Brazil Singapore

Slide 6

Slide 6 text

$BLF'FTU Google Trends of PHP Framework Japan All Countries

Slide 7

Slide 7 text

$BLF'FTU Google Trends of PHP Framework All Countries Japan CakePHP 1.2 CakePHP 1.3 CakePHP 2.0 CakePHP 3.0

Slide 8

Slide 8 text

$BLF'FTU IUUQTXXXMBODFSTKQ 6QHSBEF)JTUPSZ

Slide 9

Slide 9 text

$BLF'FTU Upgrade History (https://www.lancers.jp/) YNPSF PHP5.6 requires 2 months 1.7 year 1.8 month 1 day 2 months CakePHP2.10 requires PHP7.3 requires

Slide 10

Slide 10 text

$BLF'FTU $BLF1)1$BLF1)1 DPFYJTUFENJHSBUJPO

Slide 11

Slide 11 text

$BLF'FTU Pruduct scale (https://www.lancers.jp/) files steps Config 190 60000 Console 170 30000 Controller 350 110000 Lib 1100 153000 Model 420 105000 View 2800 240000 All 5030 698000

Slide 12

Slide 12 text

$BLF'FTU CakePHP 1.3 and 2.8 co-existed migration CakePHP1.3 CakePHP2.8

Slide 13

Slide 13 text

$BLF'FTU CakePHP 1.3 and 2.8 co-existed migration + app(app of CakePHP1.3) + config + controllers + libs + models + tests + views + webroot + cake(CakePHP1.3) CakePHP1 Model CakePHP1 Controller CakePHP1 webroot CakePHP1 View CakePHP1 Lib

Slide 14

Slide 14 text

$BLF'FTU CakePHP 1.3 and 2.8 co-existed migration + app(app of CakePHP1.3) + config + controllers + libs + models + tests + views + webroot + cake(CakePHP1.3) + vendor + cakephp + cakephp(CakePHP2.8) Install CakePHP2.8 CakePHP1 Model CakePHP1 Controller CakePHP1 webroot CakePHP1 View CakePHP1 Lib

Slide 15

Slide 15 text

$BLF'FTU CakePHP 1.3 and 2.8 co-existed migration + app(app of CakePHP1.3) + config + controllers + libs + models + tests + views + webroot + cake(CakePHP1.3) + cake28(app of CakePHP2) + Config + Test + webroot + vendor + cakephp + cakephp(CakePHP2.8) Setup CakePHP2 App CakePHP1 Model CakePHP1 Controller CakePHP1 webroot CakePHP1 View CakePHP1 Lib CakePHP2 webroot

Slide 16

Slide 16 text

$BLF'FTU CakePHP 1.3 and 2.8 co-existed migration + app(app of CakePHP1.3) + config + controllers + libs + models + tests + views + webroot + cake(CakePHP1.3) + cake28(app of CakePHP2) + Config + Lib + Model + Test + vendor + cakephp + cakephp(CakePHP2.8) Copy from CakePHP1.3 CakePHP1 Model CakePHP1 Controller CakePHP1 webroot CakePHP1 View CakePHP1 Lib CakePHP2 Model CakePHP2 Lib CakePHP2 webroot

Slide 17

Slide 17 text

$BLF'FTU CakePHP 1.3 and 2.8 co-existed migration + app(app of CakePHP1.3) + config + controllers + libs + models + tests + views + webroot + cake(CakePHP1.3) + cake28(app of CakePHP2) + Config + Controller + Lib + Model + Test + View + webroot + vendor + cakephp + cakephp(CakePHP2.8) Migrating per Controller CakePHP1 Model CakePHP1 Controller CakePHP1 webroot CakePHP1 View CakePHP1 Lib CakePHP2 Model CakePHP2 Lib CakePHP2 Controller CakePHP2 webroot CakePHP1 View

Slide 18

Slide 18 text

$BLF'FTU CakePHP 1.3 and 2.8 co-existed migration + app(app of CakePHP1.3) + config + controllers + libs + models + tests + views + webroot + cake(CakePHP1.3) + cake28(app of CakePHP2) + Config + Controller + Lib + Model + Test + View + webroot + vendor + cakephp + cakephp(CakePHP2.8) Move webroot CakePHP1 Model CakePHP1 Controller CakePHP1 webroot CakePHP1 View CakePHP1 Lib CakePHP2 Model CakePHP2 Lib CakePHP2 Controller CakePHP2 webroot CakePHP1 View

Slide 19

Slide 19 text

$BLF'FTU CakePHP 1.3 and 2.8 co-existed migration CakePHP2 Model CakePHP2 Lib CakePHP2 Controller CakePHP2 webroot CakePHP1 View + cake28(app of CakePHP2) + Config + Controller + Lib + Model + Test + View + webroot + vendor + cakephp + cakephp(CakePHP2.8) Delete CakePHP1.3

Slide 20

Slide 20 text

$BLF'FTU Upgrade per controller (or function) ●app/config/switch.yml ○Switch to CakePHP2.8 in URI units --- cakephp28: … - /mypage - /mypage/ - /mypage/index - /mypage/index/* - /mypage/charge - /mypage/charge/* … - /user/login - /user/login/* CakePHP1 Model CakePHP1 Controller CakePHP1 webroot CakePHP1 View CakePHP1 Lib CakePHP2 Model CakePHP2 Lib CakePHP2 Controller CakePHP2 webroot CakePHP1 View

Slide 21

Slide 21 text

$BLF'FTU Upgrade per Controller (or Function) ●app/webroot/index.php ○Switch to CakePHP2.8

Slide 22

Slide 22 text

$BLF'FTU Problem of per controller migration + app(app of CakePHP1.3) + config + controllers + libs + models + tests + views + cake(CakePHP1.3) + cake28(app of CakePHP2) + Config + Controller + Lib + Model + Test + View + vendor + cakephp + cakephp(CakePHP2.8) ●Both versions need to be modified ○At usual enhancement Both versions Need to be modifeid

Slide 23

Slide 23 text

$BLF'FTU $BLF1)1$BLF1)1 DPFYJTUFENJHSBUJPO

Slide 24

Slide 24 text

$BLF'FTU CakePHP 2 and 3 co-existed migration + cake28(app of CakePHP2) + Config + Controller + Lib + Model + Test + Vendor + cakephp + cakephp(CakePHP2.10) + View + vendor + cakephp + cakephp(CakePHP2.10) Move + cake28(app of CakePHP2) + Config + Controller + Lib + Model + Test + Vendor + cakephp + cakephp(CakePHP2.10) + View + vendor + cakephp + cakephp(CakePHP3.8) Install CakePHP 3

Slide 25

Slide 25 text

$BLF'FTU CakePHP 2 and 3 co-existed migration + config(config of CakePHP3) + .env + app.php + bootstrap.php + src(app of CakePHP3) + Controller + Lib + Model + cake28(app of CakePHP2) + Config(config of CakePHP2) + Controller + Lib + Model + Test(test of CakePHP2) + View + webroot(webroot of CakePHP2) + tests(test of CakePHP3) + webroot(webroot of CakePHP3) + index.php ●Setup CakePHP3 ○config ○src ■Controller ■Lib ■Model ○tests ○webroot ■index.php

Slide 26

Slide 26 text

$BLF'FTU Add config for CakePHP3 ●cake28/Config/bootstrap.php … define('CONFIG_CAKEPHP3', __DIR__ . '/../../config/'); if (!env('DB_MASTER_HOST') && file_exists(CONFIG_CAKEPHP3 . '.env')) { $dotenv = new ¥josegonzalez¥Dotenv¥Loader([CONFIG_CAKEPHP3 . '.env']); $dotenv->parse()->putenv()->toEnv()->toServer(); } try { ¥Cake¥Core¥Configure::config( 'default', new ¥Cake¥Core¥Configure¥Engine¥PhpConfig(CONFIG_CAKEPHP3) ); ¥Cake¥Core¥Configure::load('app', 'default', false); } catch (¥Exception $e) { exit($e->getMessage() . "¥n"); } ¥Cake¥Datasource¥ConnectionManager::setConfig( 'default', ¥Cake¥Core¥Configure::read('Datasources.default') ); ¥Cake¥Cache¥Cache::setConfig( '_cake_model_', ¥Cake¥Core¥Configure::read('Cache._cake_model_') ); ¥Cake¥I18n¥I18n::setLocale(¥Cake¥Core¥Configure::read('App.defaultLocale')); Add Config of CakePHP 3

Slide 27

Slide 27 text

$BLF'FTU $BLF1)1$BLF1)1 .JHSBUF-JC

Slide 28

Slide 28 text

$BLF'FTU CakePHP2 -> CakePHP3 Migrete Lib ●CakePHP2: cake28/Lib/Functions/Convert/City.php

Slide 29

Slide 29 text

$BLF'FTU CakePHP2 -> CakePHP3 Migrete Lib ●CakePHP3: src/Lib/Functions/Convert/City.php

Slide 30

Slide 30 text

$BLF'FTU $BLF1)1$BLF1)1 .JHSBUF.PEFM

Slide 31

Slide 31 text

$BLF'FTU CakePHP2 -> CakePHP3 Migrate Model ●CakePHP2: cake28/Model/City.php ['numeric'], ]; public function getName($cityId) { $prefectural = $this->findById($prefecturalId); if (isset($prefectural['Prefectural']['name']) { return null; } return $prefectural['Prefectural']['name']; } } CakePHP2 Model CakePHP2 Controller CakePHP2 webroot CakePHP2 View CakePHP2 Lib

Slide 32

Slide 32 text

$BLF'FTU CakePHP2 -> CakePHP3 Migrate Model ●Execute CakePHP3 bake command $ bin/cake bake model cities + src + Controller + Lib + Model + Entity + City.php + Table + CitiesTable.php + tests + Fixture + CitiesFixture.php + TestCase + Model + Table + CitiesTableTest.php CakePHP2 Model CakePHP2 Controller CakePHP2 webroot CakePHP2 View CakePHP2 Lib CakePHP3 Table CakePHP3 Entity

Slide 33

Slide 33 text

$BLF'FTU CakePHP2 -> CakePHP3 Migrate Model ●CakePHP2: cake28/Model/City.php public function getName(?int $cityId) : ?string { if (!isset($cityId)) { return null; } $result = $this->find()->select(['name’]) ->where(['id' => $cityId])->first(); return isset($result) ? $result->name : null; } public function __construct($id = false, $table = null, $ds = null) { parent::__construct($id, $table, $ds); $this->cake3Table = Cake¥ORM¥TableRegistry::getTableLocator()->get('Cities'); } public function getName($cityId) { return $this->cake3Table->getName($cityId); } Call CakePHP3 function ●CakePHP3: src/Model/Table/CitiesTable.php Init CakePHP3 Table CakePHP2 Model CakePHP3 Table Re-implement same function

Slide 34

Slide 34 text

$BLF'FTU CakePHP2 -> CakePHP3 Migrate Model CakePHP2 Controller CakePHP2 Model CakePHP2 webroot CakePHP3 Table CakePHP3 Entity Call same function Validate find save ●Before Migrate Controller find save CakePHP2 Test

Slide 35

Slide 35 text

$BLF'FTU CakePHP2 -> CakePHP3 Migrate Model CakePHP2 webroot CakePHP3 Table CakePHP3 Entity CakePHP3 Controller CakePHP3 webroot Validate ●After Migrate Controller CakePHP2 Model CakePHP3 Test find save find JOIN (contain) CakePHP2 Test

Slide 36

Slide 36 text

$BLF'FTU $BLF1)1$BLF1)1 .JHSBUF'PSN

Slide 37

Slide 37 text

$BLF'FTU CakePHP2 -> CakePHP3 Migrate Form CakePHP2 Controller CakePHP2 Model CakePHP2 webroot CakePHP3 Form Validate ●Before Migrate Controller public $useTable = false; $ bin/cake bake form xxxxx CakePHP2 Test CakePHP3 Test

Slide 38

Slide 38 text

$BLF'FTU CakePHP2 -> CakePHP3 Migrate Form CakePHP2 webroot CakePHP3 Form CakePHP3 Controller CakePHP3 webroot ●After Migrate Controller Validate CakePHP3 Test

Slide 39

Slide 39 text

$BLF'FTU $BLF1)1$BLF1)1 .JHSBUF$POUSPMMFS

Slide 40

Slide 40 text

$BLF'FTU CakePHP2 -> CakePHP3 Migrate Controller + src(app of CakePHP3) + Controller + Lib + Model + cake28(app of CakePHP2) + Test(UT of CakePHP2) + webroot(webroot of CakePHP2) + index.php + tests(UT of CakePHP3) + vendor + cakephp + (CakePHP3.8) CakePHP2 Controller CakePHP2 Model CakePHP2 webroot CakePHP3 Table CakePHP3 Entity

Slide 41

Slide 41 text

$BLF'FTU CakePHP2 -> CakePHP3 Migrate Controller + src(app of CakePHP3) + Controller + Lib + Model + cake28(app of CakePHP2) + Test(UT of CakePHP2) + webroot(webroot of CakePHP2) + index.php + tests(UT of CakePHP3) + vendor + cakephp + (CakePHP3.8) + webroot(webroot of CakePHP3) + index.php ●Add webroot ○for CakePHP3 CakePHP2 Controller CakePHP2 Model CakePHP2 webroot CakePHP3 Table CakePHP3 Entity CakePHP3 webroot

Slide 42

Slide 42 text

$BLF'FTU Upgrade per Controller (or Function) ●cake28/webroot/index.php ○Switch to CakePHP3

Slide 43

Slide 43 text

$BLF'FTU Upgrade per controller (or function) ●cake28/config/switch.yml ○Switch to CakePHP3 in URI units --- cakephp3: … - /mypage - /mypage/ - /mypage/index - /mypage/index/* - /mypage/charge - /mypage/charge/* … - /user/login - /user/login/* CakePHP2 Model CakePHP2 Controller CakePHP2 webroot CakePHP2 View CakePHP2 Lib CakePHP2 Table CakePHP3 Lib CakePHP3 Controller CakePHP3 webroot CakePHP3 View CakePHP3 Form

Slide 44

Slide 44 text

$BLF'FTU $BLF1)1$BLF1)1 *TJUQPTTJCMF

Slide 45

Slide 45 text

$BLF'FTU Support version PHP Min ver PHP Max ver PHPUnit Min ver PHPUnit Max ver CakePHP 2.10 5.3 7.* 3.7 5.7.* CakePHP 3.8 5.6 7.* 5.7.14 6.5 CakePHP 4 7.2 7.* 8.3.3

Slide 46

Slide 46 text

$BLF'FTU Support version PHP Min ver PHP Max ver PHPUnit Min ver PHPUnit Max ver CakePHP 2.10 5.3 7.* 3.7 5.7.* CakePHP 3.8 5.6 7.* 5.7.14 6.5 CakePHP 4 7.2 7.* 8.3.3 ●CakePHP2.10 -> CakePHP4 ○Can use PHP 7.*

Slide 47

Slide 47 text

$BLF'FTU PHPUnit support version PHP Min ver PHP Max ver PHPUnit Min ver PHPUnit Max ver CakePHP 2.10 5.3 7.* 3.7 5.7.* CakePHP 3.8 5.6 7.* 5.7.14 6.5 CakePHP 4 7.2 7.* 8.3.3 ●CakePHP2.10 -> CakePHP3 ○Can use PHPUnit 5.7.*

Slide 48

Slide 48 text

$BLF'FTU PHPUnit support version PHP Min ver PHP Max ver PHPUnit Min ver PHPUnit Max ver CakePHP 2.10 5.3 7.* 3.7 5.7.* CakePHP 3.8 5.6 7.* 5.7.14 6.5 CakePHP 4 7.2 7.* 8.3.3 ●CakePHP2.10 -> CakePHP4 ○Cannot use same version

Slide 49

Slide 49 text

$BLF'FTU PHPUnit support version PHP Min ver PHP Max ver PHPUnit Min ver PHPUnit Max ver CakePHP 2.10 5.3 7.* 3.7 5.7.* CakePHP 3.8 5.6 7.* 5.7.14 6.5 CakePHP 4 7.2 7.* 8.3.3 ●CakePHP3.8 -> CakePHP4 ○Cannot use same version

Slide 50

Slide 50 text

$BLF'FTU $PFYJTU 1)16OJUBOE1)16OJU

Slide 51

Slide 51 text

$BLF'FTU Co-Exist PHPUnit 5.7 and 8.4 + cake28(app of CakePHP2) + Config + Controller + Lib + Model + Test + Vendor + phpunit(PHPUnit5.7) + View + vendor + phpunit(PHPUnit5.7) Move + cake28(app of CakePHP2) + Config + Controller + Lib + Model + Test + Vendor + phpunit(PHPUnit5.7) + View + vendor + phpunit(PHPUnit8.4) Install PHPUnit 8

Slide 52

Slide 52 text

$BLF'FTU 5IBOL:PV

Slide 53

Slide 53 text

$BLF'FTU PHPUnit 8.3.3 in CakePHP2.10 $ ./cake28/Console/cake l_test cake28/Test/Case/Model/CityTest.php Warning Error: include(PHPUnit/Autoload.php): failed to open stream: No such file or directory in [/var/www/lancers/cake28/Vendor/cakephp/cakephp/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php, line 178] Warning Error: include(): Failed opening 'PHPUnit/Autoload.php' for inclusion (include_path='/var/www/lancers/vendor/phpunit/phpunit:/var/www/lancers/cake28/Vendor/cakephp/cak ephp/lib:/var/www/lancers/cake28/Vendor/cakephp/cakephp/lib:.:/usr/share/pear:/usr/share/php') in [/var/www/lancers/cake28/Vendor/cakephp/cakephp/lib/Cake/TestSuite/CakeTestSuiteDispatcher.php, line 178] Error: Please install PHPUnit framework v3.7 (http://www.phpunit.de) #0 /var/www/lancers/cake28/Vendor/cakephp/cakephp/lib/Cake/Console/ShellDispatcher.php(221): TestShell->initialize() #1 /var/www/lancers/cake28/Vendor/cakephp/cakephp/lib/Cake/Console/ShellDispatcher.php(66): ShellDispatcher->dispatch() #2 /var/www/lancers/cake28/Console/cake.php(56): ShellDispatcher::run(Array) #3 {main} $ ●Execute by cake command

Slide 54

Slide 54 text

$BLF'FTU PHPUnit 8.3.3 in CakePHP3 $ ./bin/phpunit --bootstrap config/bootstrap.php tests/TestCase/Model/Table/CitiesTableTest.php PHP Fatal error: Declaration of Cake¥TestSuite¥TestCase::setUp() must be compatible with PHPUnit¥Framework¥TestCase::setUp(): void in /var/www/lancers/vendor/cakephp/cakephp/src/TestSuite/TestCase.php on line 35 PHP Stack trace: PHP 1. {main}() /var/www/lancers/vendor/phpunit/phpunit/phpunit:0 PHP 2. PHPUnit¥TextUI¥Command::main() /var/www/lancers/vendor/phpunit/phpunit/phpunit:61 PHP 3. PHPUnit¥TextUI¥Command->run() … PHP 13. include() /var/www/lancers/vendor/composer/ClassLoader.php:444 $ ●Execute by phpunit command ○Requires return type declarations

Slide 55

Slide 55 text

$BLF'FTU 55 SRE 1 Person App 3 Person App 1 Person SRE 1 Person App SRE others 2017/2 Project start 2017/6 Nginx + PHP-FPM 2017/7 CakePHP1.3→2.8 start 2017/12 CakePHP Co-exist start 2018/2 2018/4 2018/5 2018/7 Batch, Admin start 2018/11 2018/12 Versionup Team App 1 Person SRE 2 Person