Laravel ๊ฐ์ ๊ฒฝ์ฐ์๋ dd()
๊ฐ ์๊ธฐ ๋๋ฌธ์ ๊ตณ์ด XDebug๋ฅผ ์ฌ์ฉํ์ง ์์๋ ํฐ ์ด๋ ค์์ ์์ง๋ง XE ๊ฐ์ ๊ฒฝ์ฐ์๋ ํ๊ฒฝ์ค์ ํ์ผ์ ๋ณ๊ฒฝํ๊ณ debugPrint()
๋ฅผ ์ฐ์ด๊ฐ๋ฉฐ ํ์ธํด์ผ ํ๊ธฐ ๋๋ฌธ์ ๋๋ฒ๊น
์ด ์ฝ์ง ์๋ค. ๊ทธ๋ฐ ๊ฒฝ์ฐ์๋ XDebug๋ฅผ ํ์ฉํ๋ฉด ํธ๋ฆฌํ๋ค.
# XDebug ์ค์น
pecl install xdebug
# ์ค์นํ์ธ
$php -v
PHP 7.1.18 (cli) (built: May 25 2018 19:18:59) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans
with Zend OPcache v7.1.18, Copyright (c) 1999-2018, by Zend Technologies
# ext-xdebug.ini ์์น ์ฐพ๊ธฐ
๋ ๊ฐ์ ๊ฒฝ์ฐ์๋ ๋ณ๋์ ext-xdebug.ini
ํ์ผ์ ์๊ณ php.ini
์ xdebug ์ค์ ์ด ํฌํจ๋จ.
php --ini
# ๋ชจ๋ ์ ์ฉ ํ์ธ ๋ฐ ํ์ฑํ
์ค์ ํ์ผ์์ ์๋์ ๊ฐ์ด ํ์ฑํ
[xdebug]
zend_extension="/usr/local/lib/php/pecl/20160303/xdebug.so"
xdebug.remote_enable=1
xdebug.remote_autostart = 1
# Visual Studio Code์์ PHP Debug ํ์ฅ ํ๋ก๊ทธ๋จ ์ค์น
- ํ์ฅ ํ๋ก๊ทธ๋จ PHP Debug ์ค์น
# ํ๊ฒฝ๋ณ์ ์ค์
.bashrc๋ .zshrc์ ์๋์ ๊ฐ์ ์ถ๊ฐ
export XDEBUG_CONFIG="idekey=VSCODE"
๊ฐ์ ์์ ํ ๋ค์๋ ์ ์ฉ
. ~/.zshrc
๋๋
. ~/.bashrc
# ๋๋ฒ๊น ํ ์คํธ
- ๋๋ฒ๊ทธ(โงโD) ๋ณด๊ธฐ๋ก ํ ํ ์์๋ฒํผ์ ๋๋ฌ ๋๋ฒ๊น ์ ์์ํ๋ค.
- ํ๊ฒฝ ์ ํ ํ๋ฉด์ด ๋์ค๋ฉด PHP ์ ํ
- PHP๋ฅผ ์ ํํ๋ฉด
launch.json
ํ์ผ์ด ๋์ค๋๋ฐ ๊ธฐ๋ณธ ์ค์ ํ์ผ์ด๊ณ ํน๋ณํ ๋ณ๊ฒฝํ ํ์๋ ์๋ค. - ์์ ์ค์ ํ์ผ์ ๋ซ๊ณ Laravel์
ExampleTest.php
ํ์ผ์ ์ด์ด๋ณธ๋ค. testBasicTest()
๋ฅผ ์๋์ ๊ฐ์ด ์์
public function testBasicTest()
{
$foo = 'bar';
$this->assertTrue(true);
}
$foo
๋ผ์ธ ์ข์ธก์ ํด๋ฆญํด์ ๋ธ๋ ์ดํฌํฌ์ธํธ๋ฅผ ์ง์ ํ๋ค.- ํฐ๋ฏธ๋์์
phpunit
์ ์คํํ๋ค. - ์ข์ธก์ ๋๋ฒ๊น
๋ทฐ๋ฅผ ๋ณด๋ฉด ์ฒ์์๋
uninitialized
์ํ์๋$foo
๊ฐ ๋จ๊ณ๋ณ ์คํ ํ"bar"
๋ก ๋ฐ๋์ด ์๋ ๊ฒ์ ํ์ธ