public function testStreamReaderIterator() { $handle = SampleDataLoader::getEmployeesCsvStream(); $expected = SampleDataLoader::getEmployeesCsv(); $fromIterator = Sequence::make(new StreamReaderIterator($handle))->reduce('', function ($content, $line) { return $content . $line; }); $this->assertEquals($expected, $fromIterator); }
public function testFileToIterator() { if (phpversion() < '5.5') { $this->assertTrue(true); return; } $handle = SampleDataLoader::getEmployeesCsvStream(); $expected = SampleDataLoader::getEmployeesCsv(); $fromIterator = Sequence::make(fileToIterator($handle))->reduce('', function ($content, $line) { return $content . $line; }); $this->assertEquals($expected, $fromIterator); }
function employeeExample1() { $employees = SampleDataLoader::getEmployees(true); // Assignment -- get a list of employees names // Get a list of employees foreach $names = array(); foreach ($employees as $employee) { $names[] = $employee['firstName']; } print_r($names); // Using a sequence $names2 = Sequence::make($employees)->pluck('firstName')->to_a(); print_r($names2); }
public function testIdentity() { $employees = SampleDataLoader::getEmployees(true); $copy = exampleIdentity($employees); $this->assertEquals($employees, $copy); }