FOSSology  4.6.0
Open Source License Compliance by Open Source Software
BulkTextExportTest.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2026 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
9 
11 use Mockery as M;
12 
17 class BulkTextExportTest extends \PHPUnit\Framework\TestCase
18 {
20  private $assertCountBefore;
21 
26  protected function setUp() : void
27  {
28  $this->assertCountBefore = \Hamcrest\MatcherAssert::getCount();
29  }
30 
35  protected function tearDown() : void
36  {
37  $this->addToAssertionCount(\Hamcrest\MatcherAssert::getCount() - $this->assertCountBefore);
38  M::close();
39  }
40 
47  {
48  $dbManager = M::mock(DbManager::class);
49  $dbManager->shouldReceive('getRows')->once()->withAnyArgs()->andReturn(array(
50  array(
51  'rf_text' => "hello, world\nsecond line",
52  'rf_shortname' => 'MIT',
53  'removing' => 'f',
54  'comment' => null,
55  'acknowledgement' => null,
56  'rf_active' => 't'
57  )
58  ));
59 
60  $bulkTextExport = new BulkTextExport($dbManager);
61  $csv = $bulkTextExport->exportBulkText();
62 
63  $handle = fopen('php://temp', 'r+');
64  fwrite($handle, $csv);
65  rewind($handle);
66 
67  $rows = array();
68  while (($row = fgetcsv($handle, 0, ',', '"')) !== false) {
69  $rows[] = $row;
70  }
71  fclose($handle);
72 
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"));
78  }
79 
84  {
85  $dbManager = M::mock(DbManager::class);
86  $bulkTextExport = new BulkTextExport($dbManager);
87 
88  $this->expectException(\InvalidArgumentException::class);
89  $bulkTextExport->setDelimiter('');
90  }
91 
96  {
97  $dbManager = M::mock(DbManager::class);
98  $bulkTextExport = new BulkTextExport($dbManager);
99 
100  $this->expectException(\InvalidArgumentException::class);
101  $bulkTextExport->setEnclosure(',');
102  }
103 }
Helper class to export license reference bulk data as CSV or JSON from the DB.
Utility functions for specific applications.