Phpunit: assertEquals(): NULL, true ๋ฐ ๋นˆ ๋ฌธ์ž์—ด์€ ๋™์ผํ•ฉ๋‹ˆ๋‹ค.

์— ๋งŒ๋“  2013๋…„ 09์›” 15์ผ  ยท  3์ฝ”๋ฉ˜ํŠธ  ยท  ์ถœ์ฒ˜: sebastianbergmann/phpunit

PHPUnit_Framework_Testcase ํด๋ž˜์Šค์—์„œ assertEquals() ๋ฉ”์„œ๋“œ๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ๋น„๊ตํ•  ๋•Œ:

_NULL_์— ๋Œ€ํ•ด _false_,
_false_์— ๋Œ€ํ•œ _๋นˆ ๋ฌธ์ž์—ด_,
_NULL_์— ๋Œ€ํ•œ _๋นˆ ๋ฌธ์ž์—ด_

๋ชจ๋“  ํ…Œ์ŠคํŠธ๋ฅผ ์„ฑ๊ณต์ ์œผ๋กœ ํ†ต๊ณผํ–ˆ์Šต๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ์–ด๋–ค ๊ฐ€์น˜๋„ ์„œ๋กœ ๋™์ผํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ assertEquals๋Š” "===" ๋˜๋Š” ์ด์™€ ์œ ์‚ฌํ•œ ๋Œ€์‹  "==" ์—ฐ์‚ฐ์ž์™€ ๋น„๊ตํ•ฉ๋‹ˆ๋‹ค. ์žˆ๋Š” ๊ทธ๋Œ€๋กœ๋ผ๊ณ  ์ƒ๊ฐํ•˜์„ธ์š”. ํ•˜์ง€๋งŒ ์™œ?

๊ฐ€์žฅ ์œ ์šฉํ•œ ๋Œ“๊ธ€

=== ๋น„๊ต๋ฅผ ์œ„ํ•œ assertSame() ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

๋ชจ๋“  3 ๋Œ“๊ธ€

=== ๋น„๊ต๋ฅผ ์œ„ํ•œ assertSame() ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

์ข‹์•„ ์™„๋ฒฝํ•ด. ์ด๋ฆ„์ด ์•ฝ๊ฐ„ ์˜คํ•ด์˜ ์†Œ์ง€๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ ๋‚ด ์ž˜๋ชป์ด์•ผ. ๊ทธ ์ฃ„์†กํ•ฉ๋‹ˆ๋‹ค.

๊ทธ๋Ÿฌ๋‚˜ assertSame() ๋Š” ๊ฐœ์ฒด๊ฐ€ ๋™์ผํ•œ ๊ฒฝ์šฐ์—๋งŒ true ๋น„๊ตํ•ฉ๋‹ˆ๋‹ค.

class Foo {}
$this->assertSame(new Foo(), new Foo());
Failed asserting that two variables reference the same object.

๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ž‘๋™ํ•  ์ˆ˜ ์žˆ๋Š” ์ฝ”๋“œ๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

$this->assertSame(new Foo(null), new Foo("")); // false

$this->assertSame(new Foo(null), new Foo(null)); // true
$this->assertSame(new Foo(""), new Foo("")); // true
์ด ํŽ˜์ด์ง€๊ฐ€ ๋„์›€์ด ๋˜์—ˆ๋‚˜์š”?
0 / 5 - 0 ๋“ฑ๊ธ‰