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',
55 'acknowledgement' =>
null,
61 $csv = $bulkTextExport->exportBulkText();
63 $handle = fopen(
'php://temp',
'r+');
64 fwrite($handle, $csv);
68 while (($row = fgetcsv($handle, 0,
',',
'"')) !==
false) {
73 $this->assertCount(2, $rows);
74 $this->assertSame(
"\xEF\xBB\xBFtext", $rows[0][0]);
75 $this->assertSame(
'hello, world\\nsecond line', $rows[1][0]);
76 $this->assertSame(
'MIT', $rows[1][1]);
77 $this->assertSame(2, substr_count($csv,
"\n"));
85 $dbManager = M::mock(DbManager::class);
88 $this->expectException(\InvalidArgumentException::class);
89 $bulkTextExport->setDelimiter(
'');
97 $dbManager = M::mock(DbManager::class);
100 $this->expectException(\InvalidArgumentException::class);
101 $bulkTextExport->setEnclosure(
',');
111 $dbManager = M::mock(DbManager::class);
112 $dbManager->shouldReceive(
'getRows')->once()->withAnyArgs()->andReturn(array(
114 'rf_text' =>
"some bulk text",
115 'rf_shortname' =>
'MIT',
118 'acknowledgement' =>
null,
120 'license_text' =>
'Permission is hereby granted, free of charge...'
123 'rf_text' =>
"some bulk text",
124 'rf_shortname' =>
'Apache-2.0',
127 'acknowledgement' =>
null,
129 'license_text' =>
'Apache License Version 2.0...'
134 $csv = $bulkTextExport->exportBulkText(0, 0,
false,
true);
136 $handle = fopen(
'php://temp',
'r+');
137 fwrite($handle, $csv);
141 while (($row = fgetcsv($handle, 0,
',',
'"')) !==
false) {
146 $this->assertCount(2, $rows);
147 $this->assertSame(
'license_text', $rows[0][6]);
148 $this->assertSame(
'MIT', $rows[1][1]);
149 $this->assertSame(
'Apache-2.0', $rows[1][2]);
150 $this->assertStringContainsString(
'Permission is hereby granted', $rows[1][6]);
151 $this->assertStringNotContainsString(
'Apache License', $rows[1][6]);
161 $dbManager = M::mock(DbManager::class);
162 $dbManager->shouldReceive(
'getRows')->once()->withAnyArgs()->andReturn(array(
164 'rf_text' =>
"some text",
165 'rf_shortname' =>
'MIT',
168 'acknowledgement' =>
null,
174 $csv = $bulkTextExport->exportBulkText();
176 $handle = fopen(
'php://temp',
'r+');
177 fwrite($handle, $csv);
181 while (($row = fgetcsv($handle, 0,
',',
'"')) !==
false) {
186 $this->assertCount(2, $rows);
187 $this->assertCount(6, $rows[0]);
188 $this->assertSame(
'is_active', $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.