Slide 1

Slide 1 text

$",&1)1ͰֶͿ ܧଓతΠϯςάϨʔγϣϯϋϯζΦϯ ։ൃฤ @PHPΧϯϑΝϨϯε෱Ԭ 2015/6/27

Slide 2

Slide 2 text

WHO? • Θͨͳ΂͔ͣͻΖ(@kaz_29) • ߹ಉձࣾ decr (decr.jp) • PHP(CakePHP)ͰWebΞϓϦ։ൃ • Πϯϑϥߏஙɾӡ༻ • iOSΞϓϦ։ൃ #beer #iosdev #cakephp #cat #camp #golf #chef #vagrant

Slide 3

Slide 3 text

WHO?

Slide 4

Slide 4 text

ಈ࡞؀ڥ

Slide 5

Slide 5 text

BeHat • ϏϔΠϏΞ(ৼ෣)ۦಈ։ൃ (BDD:Behaviour Driven Development) • ετʔϦʔϕʔεͷςεςΟϯάϑϨʔϜϫʔΫ

Slide 6

Slide 6 text

BeHat 'FBUVSFͷهड़ྫ

Slide 7

Slide 7 text

BeHat 'FBUVSFͷ࣮ߦྫ

Slide 8

Slide 8 text

BeHat #%%։ൃϓϩηε

Slide 9

Slide 9 text

࠷ॳͷεϓϦϯτ͕ ऴΘΔॴἬϫʔϓ͠·͢

Slide 10

Slide 10 text

࠷ॳͷεϓϦϯτ͕ ׬ྃͨ͠ঢ়ଶΛ࡞੒ host $ vagrant ssh develop $ cd /var/www/application/current/app $ git merge origin/step2 $ composer install --dev

Slide 11

Slide 11 text

DATABASEΛMigration

Slide 12

Slide 12 text

DATABASEΛMigration $ cd /var/www/application/current/app $ Console/cake Migrations.migration run all

Slide 13

Slide 13 text

http://192.168.33.10/posts

Slide 14

Slide 14 text

UnitTest $ cd /var/www/application/current/app $ Console/cake Test app AllTests

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

StoryTest $ cd /var/www/application/current/app $ Console/cake Bdd.story

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

Jenkinsʹ૊ࠐΜͰ͍͖·͢ʂ

Slide 19

Slide 19 text

ͦͷલʹ… $ git update-index --add --chmod=+x Console/cake $ git add -u $ git commit -m “cakeίϚϯυʹ࣮ߦݖΛ෇༩” $ git push origin master

Slide 20

Slide 20 text

BUILDπʔϧΛಋೖ — phingΛಋೖ $ cd /var/www/application/current/app $ composer require --dev "phing/phing:~2.8"

Slide 21

Slide 21 text

PHINGͷઆ໌

Slide 22

Slide 22 text

BUILDπʔϧΛಋೖ — मਖ਼Λίϛοτ $ git add composer.json composer.lock $ git commit -m 'PhingΛ௥Ճ'

Slide 23

Slide 23 text

BUILDͷઃఆ /var/www/application/current/build.xml

Slide 24

Slide 24 text

BUILDπʔϧΛಋೖ — ϏϧυΛ࣮ߦ $ cd /var/www/application/current $ app/Vendor/bin/phing

Slide 25

Slide 25 text

BUILDπʔϧΛಋೖ — मਖ਼Λίϛοτ $ git add build.xml $ git commit -m ‘ϏϧυϑΝΠϧΛ௥Ճ' $ git push origin master

Slide 26

Slide 26 text

BUILDπʔϧΛಋೖ

Slide 27

Slide 27 text

BUILDπʔϧΛಋೖ

Slide 28

Slide 28 text

BUILDπʔϧΛಋೖ cd ${WORKSPACE}/app composer install --dev cd ${WORKSPACE} app/Vendor/bin/phing -logger phing.listener.DefaultLogger

Slide 29

Slide 29 text

ϏϧυΛ࣮ߦʂ

Slide 30

Slide 30 text

UnitTest݁ՌΛදࣔ

Slide 31

Slide 31 text

UnitTest݁ՌΛදࣔ͢Δ — build.xmlΛमਖ਼

Slide 32

Slide 32 text

UnitTest݁ՌΛදࣔ͢Δ — मਖ਼Λίϛοτ $ git add build.xml $ git commit -m 'Ϣχοτςετͷ݁ՌΛϑΝΠϧ ʹग़ྗ' $ git push origin master

Slide 33

Slide 33 text

UnitTest݁ՌΛදࣔ͢Δ

Slide 34

Slide 34 text

UnitTest݁ՌΛදࣔ͢Δ app/reports/unittest.xml

Slide 35

Slide 35 text

UnitTest݁ՌΛදࣔ͢Δ

Slide 36

Slide 36 text

UnitTest݁ՌΛදࣔ͢Δ app/reports/ app/reports/coverage.xml मਖ਼ͨ͠Βอଘͯ͠Ϗϧυ࣮ߦ νΣοΫ͢Δ

Slide 37

Slide 37 text

UnitTest݁ՌΛදࣔ͢Δ

Slide 38

Slide 38 text

UnitTest݁ՌΛදࣔ͢Δ ConfigσΟϨΫτϦͷΧόϨοδ͕௿͍ʂ

Slide 39

Slide 39 text

UnitTest݁ՌΛදࣔ͢Δ — app/phpunit.xmlΛमਖ਼(ΧόϨοδͷআ֎ઃఆΛ௥Ճ) Plugin Test Vendor Config/bootstrap Config/database.php <-- ͜͜·Ͱ௥Ճ -->

Slide 40

Slide 40 text

UnitTest݁ՌΛදࣔ͢Δ — मਖ਼Λίϛοτ $ git add app/phpunit.xml $ git commit -m 'ΧόϨοδআ֎ର৅Λ௥Ճ' $ git push origin master

Slide 41

Slide 41 text

UnitTest݁ՌΛදࣔ͢Δ ΧΠθϯͨ͠ʂ

Slide 42

Slide 42 text

Behatͷ݁ՌΛදࣔ͢Δ — build.xmlΛमਖ਼ … …

Slide 43

Slide 43 text

Behatͷ݁ՌΛදࣔ͢Δ — मਖ਼Λίϛοτ $ git add build.xml $ git commit -m 'BehatςετΛ௥Ճ' $ git push origin master

Slide 44

Slide 44 text

Behatͷ݁ՌΛදࣔ͢Δ app/reports/*.xml ʹमਖ਼ मਖ਼ͨ͠Βอଘͯ͠Ϗϧυ࣮ߦ

Slide 45

Slide 45 text

Behatͷ݁ՌΛදࣔ͢Δ

Slide 46

Slide 46 text

੩తղੳͷઃఆΛ͢Δ

Slide 47

Slide 47 text

੩తղੳͷઃఆΛ͢Δ $ cd /var/www/application/current/app $ composer require --dev "cakephp/cakephp-codesniffer:0.1.*" $ composer require --dev "phpmd/phpmd:2.*" $ composer require --dev "sebastian/phpcpd:2.*"

Slide 48

Slide 48 text

੩తղੳͷઃఆΛ͢Δ — मਖ਼Λίϛοτ $ git add composer.json composer.lock $ git commit -m 'ΠϯεϖΫγϣϯπʔϧͷ௥Ճ' $ git push origin master

Slide 49

Slide 49 text

੩తղੳͷઃఆΛ͢Δ — build.xmlΛमਖ਼(1) … …

Slide 50

Slide 50 text

੩తղੳͷઃఆΛ͢Δ — build.xmlΛमਖ਼(2) - PHPCodeSnifferͷઃఆΛ௥Ճ …

Slide 51

Slide 51 text

੩తղੳͷઃఆΛ͢Δ — build.xmlΛमਖ਼(3) - PHPMDͷઃఆΛ௥Ճ …

Slide 52

Slide 52 text

੩తղੳͷઃఆΛ͢Δ — build.xmlΛमਖ਼(4) - PHPCPDͷઃఆΛ௥Ճ …

Slide 53

Slide 53 text

੩తղੳͷઃఆΛ͢Δ — मਖ਼Λίϛοτ $ git add build.xml $ git commit -m 'ΠϯεϖΫγϣϯͷ࣮ߦΛ௥Ճ' $ git push origin master

Slide 54

Slide 54 text

੩తղੳͷઃఆΛ͢Δ app/reports/checkstyle.xml app/reports/phpmd.xml app/reports/phpcpd.xml

Slide 55

Slide 55 text

੩తղੳͷઃఆΛ͢Δ MigrationͱSchemaʹܯࠂ

Slide 56

Slide 56 text

੩తղੳͷઃఆΛ͢Δ — build.xmlΛमਖ਼(5) - PHPMDͷআ֎σΟϨΫτϦ௥Ճ …

Slide 57

Slide 57 text

੩తղੳͷઃఆΛ͢Δ — मਖ਼Λίϛοτ $ git add build.xml $ git commit -m 'PMDͷআ֎σΟϨΫτϦΛ௥Ճ' $ git push origin master

Slide 58

Slide 58 text

੩తղੳͷઃఆΛ͢Δ ΧΠθϯͨ͠ʂ

Slide 59

Slide 59 text

υΩϡϝϯτΛੜ੒͢Δ — build.xmlΛमਖ਼(1) … …

Slide 60

Slide 60 text

υΩϡϝϯτΛੜ੒͢Δ $ git add build.xml $ git commit -m 'υΩϡϝϯτੜ੒ͷ࣮ߦΛ௥Ճ' $ git push origin master

Slide 61

Slide 61 text

υΩϡϝϯτΛੜ੒͢Δ

Slide 62

Slide 62 text

υΩϡϝϯτΛੜ੒͢Δ ௥ՃΛԡͯ͠ҎԼͷΑ͏ʹઃఆ app/reports/doc/ index.html API Documentation

Slide 63

Slide 63 text

υΩϡϝϯτΛੜ੒͢Δ

Slide 64

Slide 64 text

υΩϡϝϯτΛੜ੒͢Δ app/Model/Post.phpʹҎԼͷ༷ʹίϝϯτΛ௥Ճ * */ class Post extends AppModel { …

Slide 65

Slide 65 text

υΩϡϝϯτΛੜ੒͢Δ app/Model/Post.phpʹҎԼͷ༷ʹίϝϯτΛ௥Ճ class Post extends AppModel { /** * Ұཡදࣔ࣌ͷλΠτϧʹ࢖༻͢ΔΧϥϜ໊ * * @var string */ public $displayField = 'title'; /** * όϦσʔγϣϯϧʔϧ * * @var array */ public $validate = [

Slide 66

Slide 66 text

υΩϡϝϯτΛੜ੒͢Δ $ git add app/Model/Post.php $ git commit -m 'DocBlockίϝϯτΛ௥Ճ' $ git push origin master मਖ਼ͨ͠Βอଘͯ͠Ϗϧυ࣮ߦ

Slide 67

Slide 67 text

υΩϡϝϯτΛੜ੒͢Δ

Slide 68

Slide 68 text

ຊ൪؀ڥʹDEPLOY͢Δ

Slide 69

Slide 69 text

ຊ൪؀ڥʹDEPLOY͢Δ $ vagrant ssh deploy $ ssh-keygen อଘ৔ॴ,ύεϑϨʔζೖྗ(ۭͰվߦͰ) $ cat ~/.ssh/id_rsa.pub ެ։伴Λίϐʔ

Slide 70

Slide 70 text

ຊ൪؀ڥʹDEPLOY͢Δ Add deploy keyΛΫϦοΫͯ͠ެ։伴Λ௥Ճ

Slide 71

Slide 71 text

ຊ൪؀ڥʹDEPLOY͢Δ $ cd /var/www/application/current $ mkdir deploy $ cd deploy $ cap install CapistranoͷDeployεΫϦϓτͷͻͳܗΛ࡞੒

Slide 72

Slide 72 text

ຊ൪؀ڥʹDEPLOY͢Δ deploy/config/deploy/production.php 'localhost', 'MYSQL_USERNAME' => 'webapp', 'MYSQL_PASSWORD' => 'passw0rd', 'MYSQL_DB_NAME' => 'blog', 'MYSQL_PREFIX' => '', 'debug' => 0, ], function() { }); ຊ൪αʔόʔ༻ͷઃఆϑΝΠϧΛ௥Ճ

Slide 73

Slide 73 text

ຊ൪؀ڥʹDEPLOY͢Δ $ cd /var/www/application/current/deploy/config/deploy $ vim production.rb server '192.168.33.200', roles: %w{web app db}, user: 'vagrant', ssh_options: { password: fetch(:password) }, cake_env: "production", app_config:'production.php', group: 'vagrant' Deployઌͷઃఆ

Slide 74

Slide 74 text

ຊ൪؀ڥʹDEPLOY͢Δ $ cd /var/www/application/current/deploy/ $ vim reploy.rb — 5ߦ໨ͷϦϙδτϦURLΛ֤ࣗमਖ਼ set :repo_url, '[email protected]:phpcibook/blogapp.git' # (2) DeployεΫϦϓτΛमਖ਼ ϑΝΠϧͷৄࡉ͸ stypi_ deploy.rbࢀর

Slide 75

Slide 75 text

ຊ൪؀ڥʹDEPLOY͢Δ $ cd /var/www/application/current/deploy/ $ cap production deploy Please enter Server password: (): vagrant

Slide 76

Slide 76 text

։ൃฤ Fin @kaz_29