/** * Data provider to provide data to test getting ident codes via the controller * * @return array */ public function provideIdentCodeData() { $dataSet = array(); // Start with a test with a likely not configured account name $errorAccount = 'alikelyneverusedkey'; $errorResponse = new ErrorResponse(1001, "Account '{$errorAccount}' is not configured"); $dataSet[] = array(400, $errorAccount, 99999, $errorResponse); // Loop and test all configured accounts $accounts = $this->createClient()->getKernel()->getContainer()->getParameter('wk_dhl_api.b2b.accounts'); foreach ($accounts as $key => $account) { // Add items to data set with valid data $code = $account . '0099999'; $code .= IdentCode::getParityNumber($code); $dataSet[] = array(200, $key, 99999, new IdentCodeResponse($code, IdentCode::format($code))); $code = $account . '0000815'; $code .= IdentCode::getParityNumber($code); $dataSet[] = array(200, $key, 815, new IdentCodeResponse($code, IdentCode::format($code))); $code = $account . '0000003'; $code .= IdentCode::getParityNumber($code); $dataSet[] = array(200, $key, 3, new IdentCodeResponse($code, IdentCode::format($code))); // add data sets with invalid parameters $errorResponse = new ErrorResponse(1001, 'Serial number contains more than 5 digits. Start with 1 again or use modulus 100000'); $dataSet[] = array(400, $key, 999999, $errorResponse); $errorResponse = new ErrorResponse(1001, 'Serial number is no unsigned integer'); $dataSet[] = array(400, $key, 0, $errorResponse); } return $dataSet; }
/** * Tests the calculation of a parity number * * @param string $identCode * @param int $parityNumber * * @dataProvider provideParityNumberData */ public function testParityNumber($identCode, $parityNumber) { $this->assertEquals($parityNumber, IdentCode::getParityNumber($identCode)); }