I will hire your testing expertise

I need help getting tests working in my yii2 advanced app. I am fed up trying to solve it myself, I don’t have any more time to waste on this. I know how to create tests, etc. I have done it for decades on other frameworks and in other languages, it’s just this yii2 codeception testing seems IMPOSSIBLE. I just need someone to help me get the most basic tests working and I can take it from there. I have all sorts of stupid small problems like just getting routes to resolve, it’s really frustrating. This may be the first programming thing I have ever given up on. I think I just need someone with high expertise or experience in this area. Let me know if you can help. I’ll gladly PAY. Thanks.

I think I will make it without help, not that anyone jumped at the chance, but, I am starting to get results. It seems the problems were coming from files and configuration from earlier versions of yii2 where the testing setup had a completely different structure and even used other libraries. Looking at various places on the web I was finding and following inconsistent documentation. There are somewhat conflicting instructions between Yii Guide testing, the advanced template test guide, the yii2 page on the codeception website and still other sources. If I successfully adapt the new testing style with this originally yii2 beta codebase I will try to find the time to document and share it.

I don’t think I’ve ever been so frustrated. So glad to finally get results!

Would be cool if you’ll point to wrong parts in docs.

Hello samdark, I have experienced some problems too, so I will try to describe them. I am trying to create some acceptance tests in backend for yii2 advanced app. I am using phantomjs, php -S for webserver and codeception of course. After studying the configuration in yii2 basic I tried to follow the same configuration in advanced backend. So I have added the following acceptance.suite.yml




class_name: AcceptanceTester

modules:

    enabled:

        - WebDriver:

            url: http://localhost:8000/

            host: localhost 

            browser: firefox

            window_size: 1024x768

        - Yii2:

            part: [orm, fixtures] # allow to use AR methods

            entryScript: index-test.php

            cleanup: false



The main problem I have encountered is about the entry script of the application. In the advanced documentation for the frontend you propose to start the web server with php -S 127.0.0.1:8080 -t frontend/web. In the basic yii2 you propose instead to start with tests/bin/yii serve which starts a console application.

I tried different approaches and I finally decided to run the webserver with php -localhost:8000 index-test.php (for running index-test.php). So to conclude I give the following orders in different terminals:

  1. in backend/web, php -localhost:8000 index-test.php

  2. phantomjs --webdriver=4444

  3. codecept run --debug – -c backend acceptance filenamecept

For the moment I am getting an error,




[INFO  - 2017-05-17T07:34:22.455Z] SessionManagerReqHand - _postNewSessionCommand - New Session Created: 3ed11610-3ad3-11e7-98b5-691c7cb75baa

[ERROR - 2017-05-17T07:34:23.398Z] Session [3ed11610-3ad3-11e7-98b5-691c7cb75baa] - page.onError - msg: ReferenceError: Can't find variable: jQuery


  phantomjs://platform/console++.js:263 in error

[ERROR - 2017-05-17T07:34:23.399Z] Session [3ed11610-3ad3-11e7-98b5-691c7cb75baa] - page.onError - stack:

  global code (http://localhost:8000/backend-site/login:127)


  phantomjs://platform/console++.js:263 in error

[ERROR - 2017-05-17T07:34:26.473Z] Session [3ed11610-3ad3-11e7-98b5-691c7cb75baa] - page.onError - msg: ReferenceError: Can't find variable: jQuery


  phantomjs://platform/console++.js:263 in error

[ERROR - 2017-05-17T07:34:26.473Z] Session [3ed11610-3ad3-11e7-98b5-691c7cb75baa] - page.onError - stack:

  global code (http://localhost:8000/backend-site/login:127)


  phantomjs://platform/console++.js:263 in error



The question I have is this the right approach or should I use the yii_test file which is in the environments and how to use it exactly? Because in the documentation of yii2 advanced there isn’ t any example.

As you possibly understand I am not familiar with phantomjs codeception and php -S webserver, and how all these cooperate with each other.

I hope your answer will solve some of these mysteries

p.s. Last minute observation, the path in the web application is http://localhost:8000/admin/backend-site/ maybe this is also a parameter that I should think about

p.s.2 Also it seems that I should start the webserver from the frontend/web because this is where the application begins and has a ln admin/ folder that links to the backend/web. But I do not know how to call the index-test.php

p.s.3 I tried the p.s.2 meaning starting php -S localhost:8000 -t frontend/web and it starts but cannot authenticate the user which happens because I assume it uses the index.php and tries to login the application db and not the test db

For the moment I cannot figure out what to do. I followed two different approaches. First I tried to run the acceptance tests for the backend through the frontend. But this cannot happen because when I call the url which starts the backend application, it starts the index.php page, so it runs the dev configuration of the application. If I try to run the acceptance tests from the backend test folder, I am getting the following:




Signature: backend\tests\AddProtectorsByFileCest:insertProtectorsByfile

Test: tests/acceptance/AddProtectorsByFileCest.php:insertProtectorsByfile

Scenario --

 I have fixtures {"user":{"class":"common\\fixtures\\User","dataFile":"\/var\/www\/html\/akadim\/backend\/tests\/_data\/data_wi...}

  [yii\db\Connection::open] 'Opening DB connection: mysql:host=172.17.0.4;dbname=yii2advanced_test'

 I login "roza94","123456"

   I am on page "/"

  [GET] http://localhost:8000/

   I wait 1

   I see "Please, log in to access the Akadim admin panel!"

   I submit form "#login-form",{"LoginForm[username]":"roza94","LoginForm[password]":"123456"}

  [Uri] http://localhost:8000/backend-site/login

  [Method] post

  [Parameters] {"LoginForm[username]":"roza94","LoginForm[password]":"123456"}

  [Page] /backend-site/login

   I wait 2

   I see link "Αποσύνδεση","/backend-site/logout"

  [Selenium har Logs] 

  09:47:24.41 INFO - {"log":{"version":"1.2","creator":{"name":"PhantomJS","version":"2.1.1"},"pages":[{"startedDateTime":"2017-05-18T09:47:19.092Z","id":"http://localhost:8000/backend-site/login","title":"Akadim Login","pageTimings":{"onLoad":124}}],"entries":[{"startedDateTime":"2017-05-18T09:47:22.030Z","time":77,"request":{"method":"POST","url":"http://localhost:8000/backend-site/login","httpVersion":"HTTP/1.1","cookies":[],"headers":[{"name":"Accept","value":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"},{"name":"Referer","value":"http://localhost:8000/backend-site/login"},{"name":"Origin","value":"http://localhost:8000"},{"name":"User-Agent","value":"Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1"},{"name":"Content-Type","value":"application/x-www-form-urlencoded"},{"name":"Content-Length","value":"149"}],"queryString":[],"headersSize":-1,"bodySize":-1},"response":{"status":200,"statusText":"OK","httpVersion":"HTTP/1.1","cookies":[],"headers":[{"name":"Host","value":"localhost:8000"},{"name":"Connection","value":"close"},{"name":"X-Powered-By","value":"PHP/5.6.30-5+deb.sury.org~trusty+2"},{"name":"Expires","value":"Thu, 19 Nov 1981 08:52:00 GMT"},{"name":"Cache-Control","value":"no-store, no-cache, must-revalidate, post-check=0, pre-check=0"},{"name":"Pragma","value":"no-cache"},{"name":"Content-Type","value":"text/html; charset=UTF-8"}],"redirectURL":"","headersSize":-1,"bodySize":28024,"content":{"size":28024,"mimeType":"text/html; charset=UTF-8"}},"cache":{},"timings":{"blocked":0,"dns":-1,"connect":-1,"send":0,"wait":55,"receive":22,"ssl":-1},"pageref":"http://localhost:8000/backend-site/login"},{"startedDateTime":"2017-05-18T09:47:22.089Z","time":22,"request":{"method":"GET","url":"http://localhost:8000/assets/74d379b9/css/bootstrap.css","httpVersion":"HTTP/1.1","cookies":[],"headers":[{"name":"Accept","value":"text/css,*/*;q=0.1"},{"name":"Referer","value":"http://localhost:8000/backend-site/login"},{"name":"User-Agent","value":"Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1"}],"queryString":[],"headersSize":-1,"bodySize":-1},"response":{"status":200,"statusText":"OK","httpVersion":"HTTP/1.1","cookies":[],"headers":[{"name":"Host","value":"localhost:8000"},{"name":"Connection","value":"close"},{"name":"Content-Type","value":"text/css; charset=UTF-8"},{"name":"Content-Length","value":"146010"}],"redirectURL":"","headersSize":-1,"bodySize":131072,"content":{"size":131072,"mimeType":"text/css; charset=UTF-8"}},"cache":{},"timings":{"blocked":0,"dns":-1,"connect":-1,"send":0,"wait":19,"receive":3,"ssl":-1},"pageref":"http://localhost:8000/backend-site/login"},{"startedDateTime":"2017-05-18T09:47:22.090Z","time":20,"request":{"method":"GET","url":"http://localhost:8000/assets/df815fd2/css/activeform.css","httpVersion":"HTTP/1.1","cookies":[],"headers":[{"name":"Accept","value":"text/css,*/*;q=0.1"},{"name":"Referer","value":"http://localhost:8000/backend-site/login"},{"name":"User-Agent","value":"Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1"}],"queryString":[],"headersSize":-1,"bodySize":-1},"response":{"status":200,"statusText":"OK","httpVersion":"HTTP/1.1","cookies":[],"headers":[{"name":"Host","value":"localhost:8000"},{"name":"Connection","value":"close"},{"name":"Content-Type","value":"text/css; charset=UTF-8"},{"name":"Content-Length","value":"4935"}],"redirectURL":"","headersSize":-1,"bodySize":4935,"content":{"size":4935,"mimeType":"text/css; charset=UTF-8"}},"cache":{},"timings":{"blocked":0,"dns":-1,"connect":-1,"send":0,"wait":19,"receive":1,"ssl":-1},"pageref":"http://localhost:8000/backend-site/login"},{"startedDateTime":"2017-05-18T09:47:22.090Z","time":40,"request":{"method":"GET","url":"http://localhost:8000/assets/469784e5/animate.min.css","httpVersion":"HTTP/1.1","cookies":[],"headers":[{"name":"Accept","value":"text/css,*/*;q=0.1"},{"name":"Referer","value":"http://localhost:8000/backend-site/login"},{"name":"User-Agent","value":"Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1"}],"queryString":[],"headersSize":-1,"bodySize":-1},"response":{"status":200,"statusText":"OK","httpVersion":"HTTP/1.1","cookies":[],"headers":[{"name":"Host","value":"localhost:8000"},{"name":"Connection","value":"close"},{"name":"Content-Type","value":"text/css; charset=UTF-8"},{"name":"Content-Length","value":"52789"}],"redirectURL":"","headersSize":-1,"bodySize":52789,"content":{"size":52789,"mimeType":"text/css; charset=UTF-8"}},"cache":{},"timings":{"blocked":0,"dns":-1,"connect":-1,"send":0,"wait":39,"receive":1,"ssl":-1},"pageref":"http://localhost:8000/backend-site/login"},{"startedDateTime":"2017-05-18T09:47:22.091Z","time":44,"request":{"method":"GET","url":"http://localhost:8000/css/login2.css","httpVersion":"HTTP/1.1","cookies":[],"headers":[{"name":"Accept","value":"text/css,*/*;q=0.1"},{"name":"Referer","value":"http://localhost:8000/backend-site/login"},{"name":"User-Agent","value":"Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1"}],"queryString":[],"headersSize":-1,"bodySize":-1},"response":{"status":200,"statusText":"OK","httpVersion":"HTTP/1.1","cookies":[],"headers":[{"name":"Host","value":"localhost:8000"},{"name":"Connection","value":"close"},{"name":"Content-Type","value":"text/css; charset=UTF-8"},{"name":"Content-Length","value":"9258"}],"redirectURL":"","headersSize":-1,"bodySize":9258,"content":{"size":9258,"mimeType":"text/css; charset=UTF-8"}},"cache":{},"timings":{"blocked":0,"dns":-1,"connect":-1,"send":0,"wait":43,"receive":1,"ssl":-1},"pageref":"http://localhost:8000/backend-site/login"},{"startedDateTime":"2017-05-18T09:47:22.099Z","time":44,"request":{"method":"GET","url":"http://localhost:8000/assets/fa54081/jquery.js","httpVersion":"HTTP/1.1","cookies":[],"headers":[{"name":"Accept","value":"*/*"},{"name":"Referer","value":"http://localhost:8000/backend-site/login"},{"name":"User-Agent","value":"Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1"}],"queryString":[],"headersSize":-1,"bodySize":-1},"response":{"status":200,"statusText":"OK","httpVersion":"HTTP/1.1","cookies":[],"headers":[{"name":"Host","value":"localhost:8000"},{"name":"Connection","value":"close"},{"name":"Content-Type","value":"text/javascript; charset=UTF-8"},{"name":"Content-Length","value":"257551"}],"redirectURL":"","headersSize":-1,"bodySize":257551,"content":{"size":257551,"mimeType":"text/javascript; charset=UTF-8"}},"cache":{},"timings":{"blocked":0,"dns":-1,"connect":-1,"send":0,"wait":43,"receive":1,"ssl":-1},"pageref":"http://localhost:8000/backend-site/login"},{"startedDateTime":"2017-05-18T09:47:22.100Z","time":43,"request":{"method":"GET","url":"http://localhost:8000/assets/5482e21e/yii.js","httpVersion":"HTTP/1.1","cookies":[],"headers":[{"name":"Accept","value":"*/*"},{"name":"Referer","value":"http://localhost:8000/backend-site/login"},{"name":"User-Agent","value":"Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1"}],"queryString":[],"headersSize":-1,"bodySize":-1},"response":{"status":200,"statusText":"OK","httpVersion":"HTTP/1.1","cookies":[],"headers":[{"name":"Host","value":"localhost:8000"},{"name":"Connection","value":"close"},{"name":"Content-Type","value":"text/javascript; charset=UTF-8"},{"name":"Content-Length","value":"19877"}],"redirectURL":"","headersSize":-1,"bodySize":19877,"content":{"size":19877,"mimeType":"text/javascript; charset=UTF-8"}},"cache":{},"timings":{"blocked":0,"dns":-1,"connect":-1,"send":0,"wait":41,"receive":2,"ssl":-1},"pageref":"http://localhost:8000/backend-site/login"},{"startedDateTime":"2017-05-18T09:47:22.100Z","time":52,"request":{"method":"GET","url":"http://localhost:8000/assets/74d379b9/js/bootstrap.js","httpVersion":"HTTP/1.1","cookies":[],"headers":[{"name":"Accept","value":"*/*"},{"name":"Referer","value":"http://localhost:8000/backend-site/login"},{"name":"User-Agent","value":"Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1"}],"queryString":[],"headersSize":-1,"bodySize":-1},"response":{"status":200,"statusText":"OK","httpVersion":"HTTP/1.1","cookies":[],"headers":[{"name":"Host","value":"localhost:8000"},{"name":"Connection","value":"close"},{"name":"Content-Type","value":"text/javascript; charset=UTF-8"},{"name":"Content-Length","value":"69707"}],"redirectURL":"","headersSize":-1,"bodySize":69707,"content":{"size":69707,"mimeType":"text/javascript; charset=UTF-8"}},"cache":{},"timings":{"blocked":0,"dns":-1,"connect":-1,"send":0,"wait":51,"receive":1,"ssl":-1},"pageref":"http://localhost:8000/backend-site/login"},{"startedDateTime":"2017-05-18T09:47:22.101Z","time":50,"request":{"method":"GET","url":"http://localhost:8000/assets/df815fd2/js/activeform.js","httpVersion":"HTTP/1.1","cookies":[],"headers":[{"name":"Accept","value":"*/*"},{"name":"Referer","value":"http://localhost:8000/backend-site/login"},{"name":"User-Agent","value":"Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1"}],"queryString":[],"headersSize":-1,"bodySize":-1},"response":{"status":200,"statusText":"OK","httpVersion":"HTTP/1.1","cookies":[],"headers":[{"name":"Host","value":"localhost:8000"},{"name":"Connection","value":"close"},{"name":"Content-Type","value":"text/javascript; charset=UTF-8"},{"name":"Content-Length","value":"5514"}],"redirectURL":"","headersSize":-1,"bodySize":5514,"content":{"size":5514,"mimeType":"text/javascript; charset=UTF-8"}},"cache":{},"timings":{"blocked":0,"dns":-1,"connect":-1,"send":0,"wait":49,"receive":1,"ssl":-1},"pageref":"http://localhost:8000/backend-site/login"},{"startedDateTime":"2017-05-18T09:47:22.102Z","time":56,"request":{"method":"GET","url":"http://localhost:8000/assets/5482e21e/yii.validation.js","httpVersion":"HTTP/1.1","cookies":[],"headers":[{"name":"Accept","value":"*/*"},{"name":"Referer","value":"http://localhost:8000/backend-site/login"},{"name":"User-Agent","value":"Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1"}],"queryString":[],"headersSize":-1,"bodySize":-1},"response":{"status":200,"statusText":"OK","httpVersion":"HTTP/1.1","cookies":[],"headers":[{"name":"Host","value":"localhost:8000"},{"name":"Connection","value":"close"},{"name":"Content-Type","value":"text/javascript; charset=UTF-8"},{"name":"Content-Length","value":"15502"}],"redirectURL":"","headersSize":-1,"bodySize":15502,"content":{"size":15502,"mimeType":"text/javascript; charset=UTF-8"}},"cache":{},"timings":{"blocked":0,"dns":-1,"connect":-1,"send":0,"wait":54,"receive":2,"ssl":-1},"pageref":"http://localhost:8000/backend-site/login"},{"startedDateTime":"2017-05-18T09:47:22.102Z","time":56,"request":{"method":"GET","url":"http://localhost:8000/assets/5482e21e/yii.activeForm.js","httpVersion":"HTTP/1.1","cookies":[],"headers":[{"name":"Accept","value":"*/*"},{"name":"Referer","value":"http://localhost:8000/backend-site/login"},{"name":"User-Agent","value":"Mozilla/5.0 (Unknown; Linux x86_64) AppleWebKit/538.1 (KHTML, like Gecko) PhantomJS/2.1.1 Safari/538.1"}],"queryString":[],"headersSize":-1,"bodySize":-1},"response":{"status":200,"statusText":"OK","httpVersion":"HTTP/1.1","cookies":[],"headers":[{"name":"Host","value":"localhost:8000"},{"name":"Connection","value":"close"},{"name":"Content-Type","value":"text/javascript; charset=UTF-8"},{"name":"Content-Length","value":"32248"}],"redirectURL":"","headersSize":-1,"bodySize":32248,"content":{"size":32248,"mimeType":"text/javascript; charset=UTF-8"}},"cache":{},"timings":{"blocked":0,"dns":-1,"connect":-1,"send":0,"wait":55,"receive":1,"ssl":-1},"pageref":"http://localhost:8000/backend-site/login"}]}}

  

  [Selenium browser Logs]  EMPTY 

  Screenshot and page source were saved into '/var/www/html/akadim/backend/tests/_output/' dir

 FAIL 


-----------------------------------------------------------------------------------------------------------------------------------




Time: 5.84 seconds, Memory: 18.00MB


There was 1 failure:


---------

1) AddProtectorsByFileCest: Insert protectors byfile

 Test  tests/acceptance/AddProtectorsByFileCest.php:insertProtectorsByfile

 Step  See link "Αποσύνδεση","/backend-site/logout"

 Fail  No links containing text 'Αποσύνδεση' were found in page /backend-site/login


Scenario Steps:


 7. $I->seeLink("Αποσύνδεση","/backend-site/logout") at tests/_support/AcceptanceTester.php:38

 6. $I->wait(2) at tests/_support/AcceptanceTester.php:37

 5. $I->submitForm("#login-form",{"LoginForm[username]":"roza94","LoginForm[password]":"123456"}) at tests/_support/AcceptanceTester.php:36

 4. $I->see("Please, log in to access the Akadim admin panel!") at tests/_support/AcceptanceTester.php:32

 3. $I->wait(1) at tests/_support/AcceptanceTester.php:31

 2. $I->amOnPage("/") at tests/_support/AcceptanceTester.php:30




It seems that it is running at the beginning with the test configuration, but when it comes to authenticate the user it rejects him even though it gets the correct credentials. If I give the credentials for a user in the dev database the user logs in. I can’t understand why this happens. So I have the same results either way running acceptance from backend or frontend. Does anyone have any suggestion?

Do you still need tester? I was a game and program tester for 3 years

Oh, btw. I’ve updated docs. You can either check GitHub or wait till next release so these are published.