php - Data got imported (using PDO) twice when running test with Codeception -


i'm writing small script parse csv information , store in database. i'm not using framework since small project, use codeception test code.

basically class parser parsing data csv file, process data (put more neatly arrays) , insert data.

below method inserting data:

public function insertcategories() {     // prepare statement     codecept_debug("entering insertcategories");     $stmt = $this->dbo->prepare("insert `cs_menucategory` (`catid`, `menugroupid`, `categoryname`) values (:catid, :menugroupid, :categoryname)");      // prepare parameters     $cats = $this->result['category'];     ($i = 0; $i < count($cats); $i++) {         $params = array();         $params['menugroupid'] = $i+1;         $params['catid'] = $i+1;         $params['categoryname'] = $cats[$i];          // execute statement         $stmt->execute($params);     } } 

i wrote simple unit test method using codeception:

class test extends \phpunit_framework_testcase {      protected function setup() {}      protected function teardown() {}      // tests     public function test() {         $parser = new parser();         $parser->run();      } } 

in method run

public function run() {     $this->createresultarrays();     $this->getcsvdata();      $this->connectdtb();      $this->processdata();     $this->insertcategories(); } 

when ran test , checked in database, data got imported twice. tried see if method got called more once, or if loop causing problem printing out status 'flags', both weren't case.

once tried php interactive mode, however, code worked fine, data got imported once , correctly.

so ran test again in debug mode, , here returned:

    vy-huynhs:menudrive vyhuynh$ ./vendor/bin/codecept run unit test --debug     codeception php testing framework v2.1.5     powered phpunit 4.8.22 sebastian bergmann , contributors.        group 'failed' empty, no tests loaded       entering insertcategories      unit tests (1) ------------------------------     modules: asserts, \helper\unit     ---------------------------------------------     running test::test...        entering insertcategories     test::test                             ok     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^     ---------------------------------------------       time: 225 ms, memory: 9.50mb      ok (1 test, 0 assertions)     vy-huynhs:menudrive vyhuynh$  

i suspect causing error:

group 'failed' empty, no tests loaded

maybe there configurations codeception didn't correctly.

below content of csv file:

group,category,item  main menu,appetizers,buffalo wings  ,,chicken fingers  ,,french fries  ,salad,caesar salad  ,,house salad  breakfast menu,sandwiches,blt  ,drinks,coffee  ,,tea  

and script tried importing data category column.

thank all.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -