20 private $assertCountBefore;
26 protected function setUp() : void
28 $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
37 $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount() - $this->assertCountBefore);
48 $dbManager = M::mock(DbManager::class);
49 $dbManager->shouldReceive(
'getRows')->once()->withAnyArgs()->andReturn(array(
51 'rf_text' =>
"hello, world\nsecond line",
52 'rf_shortname' =>
'MIT',
56 'acknowledgement' =>
null,
62 $csv = $bulkTextExport->exportBulkText();
64 $handle = fopen(
'php://temp',
'r+');
65 fwrite($handle, $csv);
69 while (($row = fgetcsv($handle, 0,
',',
'"')) !==
false) {
74 $this->assertCount(2, $rows);
75 $this->assertSame(
"\xEF\xBB\xBFText", $rows[0][0]);
76 $this->assertSame(
'hello, world\\nsecond line', $rows[1][0]);
77 $this->assertSame(
'MIT', $rows[1][2]);
78 $this->assertSame(2, substr_count($csv,
"\n"));
86 $dbManager = M::mock(DbManager::class);
89 $this->expectException(\InvalidArgumentException::class);
90 $bulkTextExport->setDelimiter(
'');
98 $dbManager = M::mock(DbManager::class);
101 $this->expectException(\InvalidArgumentException::class);
102 $bulkTextExport->setEnclosure(
',');
112 $dbManager = M::mock(DbManager::class);
113 $dbManager->shouldReceive(
'getRows')->once()->withAnyArgs()->andReturn(array(
115 'rf_text' =>
"some bulk text",
116 'rf_shortname' =>
'MIT',
119 'reportinfo' =>
null,
120 'acknowledgement' =>
null,
122 'license_text' =>
'Permission is hereby granted, free of charge...'
125 'rf_text' =>
"some bulk text",
126 'rf_shortname' =>
'Apache-2.0',
129 'reportinfo' =>
null,
130 'acknowledgement' =>
null,
132 'license_text' =>
'Apache License Version 2.0...'
137 $csv = $bulkTextExport->exportBulkText(0, 0,
false,
true);
139 $handle = fopen(
'php://temp',
'r+');
140 fwrite($handle, $csv);
144 while (($row = fgetcsv($handle, 0,
',',
'"')) !==
false) {
150 $this->assertCount(3, $rows);
151 $this->assertSame(
'license_ref_text', $rows[0][7]);
152 $this->assertSame(
'MIT', $rows[1][2]);
153 $this->assertSame(
'Apache-2.0', $rows[2][2]);
154 $this->assertStringContainsString(
'Permission is hereby granted', $rows[1][7]);
155 $this->assertStringNotContainsString(
'Apache License', $rows[1][7]);
156 $this->assertStringContainsString(
'Apache License', $rows[2][7]);
166 $dbManager = M::mock(DbManager::class);
167 $dbManager->shouldReceive(
'getRows')->once()->withAnyArgs()->andReturn(array(
169 'rf_text' =>
"some text",
170 'rf_shortname' =>
'MIT',
173 'reportinfo' =>
null,
174 'acknowledgement' =>
null,
180 $csv = $bulkTextExport->exportBulkText();
182 $handle = fopen(
'php://temp',
'r+');
183 fwrite($handle, $csv);
187 while (($row = fgetcsv($handle, 0,
',',
'"')) !==
false) {
192 $this->assertCount(2, $rows);
193 $this->assertCount(7, $rows[0]);
194 $this->assertSame(
'License Text', $rows[0][5]);
Test for class BulkTextExport.
setUp()
One time setup for test.
testExportBulkTextCsvEscapesDelimiterAndNewlineInText()
testSetDelimiterRejectsEmptyValue()
testExportBulkTextCsvExcludesLicenseTextByDefault()
testExportBulkTextCsvIncludesLicenseText()
testSetEnclosureRejectsSameValueAsDelimiter()
Helper class to export license reference bulk data as CSV or JSON from the DB.
Utility functions for specific applications.