{"id":160,"date":"2019-07-07T20:38:54","date_gmt":"2019-07-07T20:38:54","guid":{"rendered":"https:\/\/www.369usa.com\/blog\/?p=160"},"modified":"2019-07-08T14:20:46","modified_gmt":"2019-07-08T14:20:46","slug":"some-notes-about-docker-phpunit","status":"publish","type":"post","link":"https:\/\/www.369usa.com\/blog\/some-notes-about-docker-phpunit\/","title":{"rendered":"Some Notes about Docker + PHPUnit"},"content":{"rendered":"<p>This is kinda a confusing subject to learn for me, especially when I am not very familiar with docker yet, nor with PHPUnit. Here is my note as I go along the study process.<\/p>\n<p>Source Link:<br \/>\nOfficial documentation for PhpUnit<br \/>\n<a href=\"https:\/\/phpunit.de\/getting-started\/phpunit-6.html\">https:\/\/phpunit.de\/getting-started\/phpunit-6.html<\/a><\/p>\n<p>Command to install PHPUnit:<\/p>\n<pre>\r\ncomposer require --dev phpunit\/phpunit ^6\r\n<\/pre>\n<p>Source Link:<br \/>\n<a href=\"https:\/\/phpunit.de\/manual\/6.5\/en\/organizing-tests.html\">https:\/\/phpunit.de\/manual\/6.5\/en\/organizing-tests.html<\/a><br \/>\nComposing a Test Suite Using XML Configuration:<\/p>\n<pre>\r\n&lt;phpunit bootstrap=&quot;src\/autoload.php&quot;&gt;\r\n  &lt;testsuites&gt;\r\n    &lt;testsuite name=&quot;money&quot;&gt;\r\n      &lt;file&gt;tests\/IntlFormatterTest.php&lt;\/file&gt;\r\n      &lt;file&gt;tests\/MoneyTest.php&lt;\/file&gt;\r\n      &lt;file&gt;tests\/CurrencyTest.php&lt;\/file&gt;\r\n      &lt;exclude&gt;some file or directory name&lt;\/exclude&gt;\r\n    &lt;\/testsuite&gt;\r\n  &lt;\/testsuites&gt;\r\n&lt;\/phpunit&gt;\r\n<\/pre>\n<p>Command to run PHPunit test:<\/p>\n<pre>\r\n.\/vendor\/bin\/phpunit --bootstrap vendor\/autoload.php tests\/testExample\r\n.\/vendor\/bin\/phpunit --bootstrap vendor\/autoload.php --testsuite msg\r\n<\/pre>\n<p>Yet, I am still a bit confused about this whole thing.<\/p>\n<p>Run commands through Docker:<br \/>\nSource link:<br \/>\n<a href=\"https:\/\/www.shiphp.com\/blog\/2017\/phpunit-docker\">https:\/\/www.shiphp.com\/blog\/2017\/phpunit-docker<\/a><\/p>\n<pre>\r\n\/\/Install PhpUnit:\r\ndocker run --rm -v $(pwd):\/app composer\/composer:latest require --dev phpunit\/phpunit ^6.0\r\n\/\/Run test suite:\r\ndocker run -v $(pwd):\/app --rm phpunit\/phpunit:latest --bootstrap vendor\/autoload.php --testsuite msg\r\n<\/pre>\n<p>* Note:<br \/>\n(above flags orders don&#8217;t matter)<br \/>\n&#8211; -rm is a flag of &#8220;clean up&#8221;.<\/p>\n<p>Access to mysql from a container:<\/p>\n<pre>\r\ndocker exec -t &lt;container_name&gt; mysql -u&lt;username&gt; -p\r\ndocker exec -it dockie_db_1 mysql -uroot -p \r\n<\/pre>\n<p>PHPUnit mock usage:<\/p>\n<pre>\r\nuse PHPUnit\\Framework\\TestCase;\r\n\r\nfunction quickTest($obj,$value=665){\r\n\treturn $obj->increaseOne($value);\r\n}\r\n\r\nclass SomeClass{\r\n\tpublic function increaseOne($value){\r\n\t\treturn $value + 1;\r\n\t}\r\n}\r\n\r\nclass testExample extends TestCase {\r\n    public function testSimple() {\r\n        \r\n        $this->assertEquals(2,2);\r\n    \r\n\t}\r\n\tpublic function testMocks() {\r\n\r\n\t\t$someClass = $this->createMock('SomeClass');\r\n\r\n\t\t$someClass->expects($this->any())\r\n\t\t\t->method('increaseOne')\r\n\t\t\t->with(665)\r\n    \t\t->will($this->returnValue(666));\r\n\r\n\t\t$b = quickTest($someClass);\r\n\r\n\t\t$this->assertEquals($b,666);\r\n        }\r\n }\r\n<\/pre>\n<p>More info about mock usage:<br \/>\n<a href=\"https:\/\/codeutopia.net\/blog\/2009\/06\/26\/unit-testing-4-mock-objects-and-testing-code-which-uses-the-database\/\">https:\/\/codeutopia.net\/blog\/2009\/06\/26\/unit-testing-4-mock-objects-and-testing-code-which-uses-the-database\/<\/a><br \/>\n<a href=\"https:\/\/stackoverflow.com\/questions\/5837991\/in-phpunit-how-do-i-indicate-different-with-on-successive-calls-to-a-mocked-m\">https:\/\/stackoverflow.com\/questions\/5837991\/in-phpunit-how-do-i-indicate-different-with-on-successive-calls-to-a-mocked-m<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is kinda a confusing subject to learn for me, especially when I am not very familiar with docker yet, nor with PHPUnit. Here is my note as I go along the study process. Source Link: Official documentation for PhpUnit https:\/\/phpunit.de\/getting-started\/phpunit-6.html Command to install PHPUnit: composer require &#8211;dev phpunit\/phpunit ^6 Source Link: https:\/\/phpunit.de\/manual\/6.5\/en\/organizing-tests.html Composing a &hellip; <a href=\"https:\/\/www.369usa.com\/blog\/some-notes-about-docker-phpunit\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Some Notes about Docker + PHPUnit&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-160","post","type-post","status-publish","format-standard","hentry","category-4"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Some Notes about Docker + PHPUnit - \u7ebd\u7ea6\u7f51\u7ad9\u8bbe\u8ba1\u535a\u5ba2<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.369usa.com\/blog\/some-notes-about-docker-phpunit\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Some Notes about Docker + PHPUnit - \u7ebd\u7ea6\u7f51\u7ad9\u8bbe\u8ba1\u535a\u5ba2\" \/>\n<meta property=\"og:description\" content=\"This is kinda a confusing subject to learn for me, especially when I am not very familiar with docker yet, nor with PHPUnit. Here is my note as I go along the study process. Source Link: Official documentation for PhpUnit https:\/\/phpunit.de\/getting-started\/phpunit-6.html Command to install PHPUnit: composer require --dev phpunit\/phpunit ^6 Source Link: https:\/\/phpunit.de\/manual\/6.5\/en\/organizing-tests.html Composing a &hellip; Continue reading &quot;Some Notes about Docker + PHPUnit&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.369usa.com\/blog\/some-notes-about-docker-phpunit\/\" \/>\n<meta property=\"og:site_name\" content=\"\u7ebd\u7ea6\u7f51\u7ad9\u8bbe\u8ba1\u535a\u5ba2\" \/>\n<meta property=\"article:published_time\" content=\"2019-07-07T20:38:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-07-08T14:20:46+00:00\" \/>\n<meta name=\"author\" content=\"darkersss\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"darkersss\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.369usa.com\/blog\/some-notes-about-docker-phpunit\/\",\"url\":\"https:\/\/www.369usa.com\/blog\/some-notes-about-docker-phpunit\/\",\"name\":\"Some Notes about Docker + PHPUnit - \u7ebd\u7ea6\u7f51\u7ad9\u8bbe\u8ba1\u535a\u5ba2\",\"isPartOf\":{\"@id\":\"https:\/\/www.369usa.com\/blog\/#website\"},\"datePublished\":\"2019-07-07T20:38:54+00:00\",\"dateModified\":\"2019-07-08T14:20:46+00:00\",\"author\":{\"@id\":\"https:\/\/www.369usa.com\/blog\/#\/schema\/person\/1c260c42af4aadda7f89a0081f6591b6\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.369usa.com\/blog\/some-notes-about-docker-phpunit\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.369usa.com\/blog\/some-notes-about-docker-phpunit\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.369usa.com\/blog\/some-notes-about-docker-phpunit\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.369usa.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Some Notes about Docker + PHPUnit\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.369usa.com\/blog\/#website\",\"url\":\"https:\/\/www.369usa.com\/blog\/\",\"name\":\"369\u7ebd\u7ea6\u7f51\u7ad9\u8bbe\u8ba1\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.369usa.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.369usa.com\/blog\/#\/schema\/person\/1c260c42af4aadda7f89a0081f6591b6\",\"name\":\"darkersss\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.369usa.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2c538d84b753eed6f6f714becf9b3955?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/2c538d84b753eed6f6f714becf9b3955?s=96&d=mm&r=g\",\"caption\":\"darkersss\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Some Notes about Docker + PHPUnit - \u7ebd\u7ea6\u7f51\u7ad9\u8bbe\u8ba1\u535a\u5ba2","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.369usa.com\/blog\/some-notes-about-docker-phpunit\/","og_locale":"en_US","og_type":"article","og_title":"Some Notes about Docker + PHPUnit - \u7ebd\u7ea6\u7f51\u7ad9\u8bbe\u8ba1\u535a\u5ba2","og_description":"This is kinda a confusing subject to learn for me, especially when I am not very familiar with docker yet, nor with PHPUnit. Here is my note as I go along the study process. Source Link: Official documentation for PhpUnit https:\/\/phpunit.de\/getting-started\/phpunit-6.html Command to install PHPUnit: composer require --dev phpunit\/phpunit ^6 Source Link: https:\/\/phpunit.de\/manual\/6.5\/en\/organizing-tests.html Composing a &hellip; Continue reading \"Some Notes about Docker + PHPUnit\"","og_url":"https:\/\/www.369usa.com\/blog\/some-notes-about-docker-phpunit\/","og_site_name":"\u7ebd\u7ea6\u7f51\u7ad9\u8bbe\u8ba1\u535a\u5ba2","article_published_time":"2019-07-07T20:38:54+00:00","article_modified_time":"2019-07-08T14:20:46+00:00","author":"darkersss","twitter_card":"summary_large_image","twitter_misc":{"Written by":"darkersss","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.369usa.com\/blog\/some-notes-about-docker-phpunit\/","url":"https:\/\/www.369usa.com\/blog\/some-notes-about-docker-phpunit\/","name":"Some Notes about Docker + PHPUnit - \u7ebd\u7ea6\u7f51\u7ad9\u8bbe\u8ba1\u535a\u5ba2","isPartOf":{"@id":"https:\/\/www.369usa.com\/blog\/#website"},"datePublished":"2019-07-07T20:38:54+00:00","dateModified":"2019-07-08T14:20:46+00:00","author":{"@id":"https:\/\/www.369usa.com\/blog\/#\/schema\/person\/1c260c42af4aadda7f89a0081f6591b6"},"breadcrumb":{"@id":"https:\/\/www.369usa.com\/blog\/some-notes-about-docker-phpunit\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.369usa.com\/blog\/some-notes-about-docker-phpunit\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.369usa.com\/blog\/some-notes-about-docker-phpunit\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.369usa.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Some Notes about Docker + PHPUnit"}]},{"@type":"WebSite","@id":"https:\/\/www.369usa.com\/blog\/#website","url":"https:\/\/www.369usa.com\/blog\/","name":"369\u7ebd\u7ea6\u7f51\u7ad9\u8bbe\u8ba1","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.369usa.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.369usa.com\/blog\/#\/schema\/person\/1c260c42af4aadda7f89a0081f6591b6","name":"darkersss","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.369usa.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/2c538d84b753eed6f6f714becf9b3955?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2c538d84b753eed6f6f714becf9b3955?s=96&d=mm&r=g","caption":"darkersss"}}]}},"_links":{"self":[{"href":"https:\/\/www.369usa.com\/blog\/wp-json\/wp\/v2\/posts\/160"}],"collection":[{"href":"https:\/\/www.369usa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.369usa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.369usa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.369usa.com\/blog\/wp-json\/wp\/v2\/comments?post=160"}],"version-history":[{"count":16,"href":"https:\/\/www.369usa.com\/blog\/wp-json\/wp\/v2\/posts\/160\/revisions"}],"predecessor-version":[{"id":176,"href":"https:\/\/www.369usa.com\/blog\/wp-json\/wp\/v2\/posts\/160\/revisions\/176"}],"wp:attachment":[{"href":"https:\/\/www.369usa.com\/blog\/wp-json\/wp\/v2\/media?parent=160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.369usa.com\/blog\/wp-json\/wp\/v2\/categories?post=160"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.369usa.com\/blog\/wp-json\/wp\/v2\/tags?post=160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}