Home > PHPUnit, Troubleshoting, Uncategorized > Instalasi PHPUnit 3.6.x di XAMPP

Instalasi PHPUnit 3.6.x di XAMPP

PHPUnit Logo

Update dari artikel sebelumnya, ternyata instalasi PHPUnit 3.6.x jauh lebih mudah. Terutama setelah saya sedikit mengetahui seluk beluk perintah pada PEAR.

Beberapa hal yang harus dipersiapkan

  • Koneksi Internet
  • XAMPP 1.7.4
  • path\to\php.exe sudah didaftarkan ke Environtment Path, misalnya E:\xampp\php

Jika semua persiapan sudah lengkap, buka command promp lalu arahkan ke folder instalasi php, dalam kasus saya E:\xampp\php.

cd E:\xampp\php

Setelah masuk ke dalam folder instalasi php, jalankan perintah berikut.

pear upgrade PEAR

Hal tersebut bertujuan untuk mengupgrade PEAR Installer, karena PHPUnit (dan beberapa package baru) membutuhkan PEAR Installer versi 1.9.4 ke atas. Tunggu hingga proses upgrade selesai. Setelah itu, jalankan perintah-perintah berikut.

pear config-set auto_discover 1

pear install pear.phpunit.de/PHPUnit

Tunggu hingga proses instalasi PHPUnit selesai. Apabila selesai, maka PHPUnit (seharusnya) sudah berhasil diinstal. Untuk memeriksa apakah PHPUnit sudah terinstal, coba jalankan perintah berikut.

phpunit --version

Apabila PHPUnit sudah berhasil terinstal, seharusnya akan muncul tulisan.

E:\xampp\php>phpunit --version

PHPUnit 3.6.4 by Sebastian Bergmann.

Untuk lebih meyakinkan apakah PHPUnit sudah berjalan dengan benar, mari kita mencoba membuat test sederhana. Buatlah file php di sembarang folder, lalu namakan dengan StackTest.php, misalnya kita letakkan di E:\xampp\htdocs\test\StackTest.php. Lalu ketikkan perintah berikut di dalamnya.

<!--?php class StackTest extends PHPUnit_Framework_TestCase {     public function testPushAndPop()     {         $stack = array();         $this--->assertEquals(0, count($stack));

        array_push($stack, 'foo');

        $this->assertEquals('foo', $stack[count($stack)-1]);

        $this->assertEquals(1, count($stack));

        $this->assertEquals('foo', array_pop($stack));

        $this->assertEquals(0, count($stack));

    }

}

Simpan, lalu jalankan command promp. Masuk ke folder tempat file StackTest.php tersebut.

cd E:\xampp\htdocs\test

Setelah itu jalankan perintah berikut

phpunit StackTest.php

Apabila PHPUnit berjalan dengan baik, maka kita akan melihat hasil test sebagai berikut.

E:\xampp\htdocs\test>phpunit StackTest.php

PHPUnit 3.6.4 by Sebastian Bergmann.

.

Time: 0 seconds, Memory: 2.75Mb

OK (1 test, 5 assertions)

Selamat Mencoba!!!

Advertisement
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.