PHPUnit Introductory case, PHPUnit introductory case _php Tutorial

Source: Internet
Author: User
Tags netbeans

PHPUnit Introductory case, PHPUnit introductory case


Understand PHPUnit

This case is an introductory case for a unit test that creates a triangle, NetBeans environment, about building in this environment PHPUnit no longer described here, you can complete the construction work by referring to the following information:

Http://www.cnblogs.com/x3d/p/phpunit-in-netbeans8.html

Https://phpunit.de/manual/current/zh_cn/installation.html

Https://github.com/sebastianbergmann/phpunit-skeleton-generator

The original code class:

 Initside ($a, $b, $c); }/** * Initializes the tri-side * @param int $a * @param int $b * @param int $c */protected function initside (&am        p; $a = 0, & $b = 0, & $c = 0) {$this->a = intval ($a);        $this->b = intval ($b);        $this->c = intval ($c);    return $this; }/** * Build * * Public Function Create ($a, $b, $c) {return $this->initside ($a, $b, $c)->verif    Ysideisvalid ();    }/** * Get type */Public function GetType () {return $this->verifytype ()->type; }/** * Verify that the three sides are valid * @return Boolean */protected function Verifysideisvalid () {if (Intval ($thi S->a) <= 0 | | Intval ($this->b) <= 0 | |        Intval ($this->c) <= 0) {return false;        if ($this->a + $this->b <= $this->c) {return false;        if ($this->a + $this->c <= $this->b) {return false; } if ($thiS->b + $this->c <= $this->a) {return false;        } if ($this->a-$this->b >= $this->c) {return false;        } if ($this->a-$this->c >= $this->b) {return false;        } if ($this->b-$this->c >= $this->a) {return false;    } return true; }/** * Authentication type */protected function Verifytype () {if ($this->isequilateral ()) {$thi            S->type = self::type_equilateral;        return $this;            } if ($this->isisosceles ()) {$this->type = self::type_isosceles;        return $this;        } $this->type = Self::type_ordinary;    return $this; }/** * is equilateral triangle */protected function isequilateral () {return ($this->a = = $this->b) &am p;& ($this->b = = $this->c))?    True:false; }/** * is isosceles triangle */protected function IsisosceLes () {return ($this->a = = $this->b) | | ($this->b = = $this->c) | | ($this->a = = $this->c)) ?    True:false; }}

Generated test class files:

 object = new Triangle;     }/** * Tears down the fixture, for example, closes a network connection.     * This method was called after a test is executed. */protected function TearDown () {}/** * @dataProvider Adddataprovider * @covers triangle::c     reate * @todo Implement testcreate ().        */Public Function testcreate ($a, $b, $c) {//Remove The following lines if you implement this test.          /** $this->marktestincomplete (' This test have not been implemented yet. '         );    * */* Implementation code */$this->asserttrue ($this->object->create ($a, $b, $c));     }/** * @covers triangle::gettype * @todo Implement testgettype ().        */Public Function Testgettype () {//Remove The following lines if you implement this test.        $this->marktestincomplete (' This test have not been implemented yet. '    );    }/** * Test case * @return Array */Public function Adddataprovider () {return [[3, 4, 5],//yes [ 2, 2, 2],//yes [8, ten, 8],//yes [2, 3, 4],//yes [1, 2, 3],//no [5, 6, 7],        Yes [8, 8, +],//yes [0, 0, 0],//no [ -10, 2, 5],//no [0, 2, 1],//no    ]; }}

It is important to note that the test file class generated after we perform the "Create/Update Test" is somewhat different from the above, where the test case is manually added, where the implementation can be seen in the manual!

Attached results:

"/usr/bin/php" "/usr/local/bin/phpunit" "--colors" "--log-junit" "/tmp/nb-phpunit-log.xml" "--bootstrap" "/var/www/ html/phpunit/test/bootstrap.php ""/usr/local/netbeans-8.1/php/phpunit/netbeanssuite.php ""--""--run=/var/www/ html/phpunit/test/core/triangletest.php "PHPUnit 5.2.10 by Sebastian Bergmann and contributors ..... F.. Fffi 11/11 (100%) time:105 MS, memory:10.50mbthere were 4 failure s:1) triangletest::testcreate with Data set #4 (1, 2, 3) Failed asserting that's false is True./var/www/html/phpunit/test/cor e/triangletest.php:472) triangletest::testcreate with Data set #7 (0, 0, 0) Failed asserting that's false is True./var/www/ht ml/phpunit/test/core/triangletest.php:473) triangletest::testcreate with Data set #8 ( -10, 2, 5) Failed asserting that FAL SE is true./var/www/html/phpunit/test/core/triangletest.php:474) triangletest::testcreate with Data set #9 (0, 2, 1) Failed asserting that's false is True./var/www/html/phpunit/test/core/triangletest.php:47failures! Tests:11, Assertions:10, Failures:4, incomplete:1. Complete.

  

http://www.bkjia.com/PHPjc/1108859.html www.bkjia.com true http://www.bkjia.com/PHPjc/1108859.html techarticle PHPUnit Getting Started case, PHPUnit Getting Started case study PHPUnit This case is an introductory example of a unit test for creating a triangle, completed in the NetBeans environment, about this environment ...

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.