我有我的測試問題。我不知道爲什麼我的函數是未定義的。我添加使用狀態,phpstorm看到這個類。但是當運行測試錯誤與undefined。symfony test未定義函數
namespace tests\AppBundle\Parser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use AppBundle\Parser\CommissionDataParser;
class CommissionDataParserTest extends WebTestCase
{
public function testGroupOrdersByWeek()
{
$orders = [
0 => [
'date' => '2016-01-10',
'client_id' => '2',
'client_type'=> 'natural',
'operation_type' => 'cash_in',
'operation_sum' => '200.00',
'operation_currency' => 'EUR',
],
1 => [
'date' => '2016-01-05',
'client_id' => '1',
'client_type'=> 'legal',
'operation_type' => 'cash_out',
'operation_sum' => '300.00',
'operation_currency' => 'EUR',
],
2 => [
'date' => '2016-01-11',
'client_id' => '1',
'client_type'=> 'natural',
'operation_type' => 'cash_out',
'operation_sum' => '30000',
'operation_currency' => 'JPY'
]
];
$expected = [
0 => [
'date' => '2016-01-05',
'client_id' => '2',
'client_type'=> 'natural',
'operation_type' => 'cash_in',
'operation_sum' => '200.00',
'operation_currency' => 'EUR',
],
1 => [
'date' => '2016-01-10',
'client_id' => '1',
'client_type'=> 'legal',
'operation_type' => 'cash_out',
'operation_sum' => '300.00',
'operation_currency' => 'EUR',
],
2 => [
'date' => '2016-01-11',
'client_id' => '1',
'client_type'=> 'natural',
'operation_type' => 'cash_out',
'operation_sum' => '30000',
'operation_currency' => 'JPY'
]
];
$um = new CommissionDataParser();
$result = $um->groupOrdersByWeek($orders);
$this->assertEquals($expected, $result, '**** -->>>>> result array wrong');
}
有功能,我想測試一下:我把這個類的小部分,例如
namespace AppBundle\Parser;
class CommissionDataParser
{
public function getData($file)
{
$orders = $this->extractOrders($file);
if (is_array($orders)) {
$orders = $this->groupOrdersByWeek($orders);
}
// ...
}
public function extractOrders($file)
{
$orders = [];
$data = [];
//$lines = explode(PHP_EOL, file_get_contents($file));
if (($handle = fopen($file, "r")) !== FALSE) {
while (($row = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($row);
if ($num !== 6) {
return 'Badly structured file';
} else if ($num == 0) {
return 'file is empty';
}
$data[] = $row;
}
fclose($handle);
}
foreach ($data as $row)
{
$orders[] = [
'date' => $row[0],
'client_id' => $row[1],
'client_type' => $row[2],
'operation_type' => $row[3],
'operation_sum' => $row[4],
'operation_currency' => $row[5]
];
}
return $orders;
}
ü可以粘貼在這裏üCommissionDataParser的代碼? –