-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #6 Fix Visual FoxPro interpreting problem
- Loading branch information
Showing
6 changed files
with
187 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: Michał Kowalik <maf.michal@gmail.com> | ||
* Date: 22.01.17 22:59 | ||
*/ | ||
|
||
namespace org\majkel\dbase\format; | ||
|
||
use org\majkel\dbase\Field; | ||
use org\majkel\dbase\Format; | ||
|
||
/** | ||
* Class FoxPro | ||
* | ||
* @package org\majkel\dbase\format | ||
* | ||
* @author Michał Kowalik <maf.michal@gmail.com> | ||
*/ | ||
class FoxPro extends Format { | ||
|
||
const NAME = 'FoxPro'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function createHeader($data) { | ||
$header = parent::createHeader($data); | ||
return $header->setValid($header->getVersion() & $this->getVersion()); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function supportsType($type) { | ||
return in_array($type, array(Field::TYPE_CHARACTER, Field::TYPE_DATE, | ||
Field::TYPE_LOGICAL, Field::TYPE_MEMO, Field::TYPE_NUMERIC)); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getType() { | ||
return Format::FOXPRO; | ||
} | ||
|
||
/** | ||
* @return integer | ||
*/ | ||
protected function getVersion() { | ||
return 0x30; | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: Michał Kowalik <maf.michal@gmail.com> | ||
* Date: 22.01.17 22:10 | ||
*/ | ||
|
||
namespace org\majkel\dbase; | ||
|
||
use org\majkel\dbase\tests\utils\TestBase; | ||
|
||
/** | ||
* Class Issue6Test | ||
* | ||
* @author Michał Kowalik <maf.michal@gmail.com> | ||
* | ||
* @coversDefaultClass \org\majkel\dbase\format\FoxPro | ||
*/ | ||
class Issue6Test extends TestBase | ||
{ | ||
/** | ||
* @test | ||
* @throws Exception | ||
* @throws \PHPUnit_Framework_AssertionFailedError | ||
*/ | ||
public function testLoadFoxProFile() | ||
{ | ||
$table = Table::fromFile("tests/fixtures/issue-6-example-file.dbf"); | ||
self::assertSame(3, $table->getRecordsCount()); | ||
self::assertSame(8, $table->getFieldsCount()); | ||
self::assertSame($table->getField('DFD')->getType(), Field::TYPE_CHARACTER); | ||
self::assertSame($table->getField('FDA')->getType(), Field::TYPE_CHARACTER); | ||
self::assertSame($table->getField('FDAS')->getType(), Field::TYPE_CHARACTER); | ||
self::assertSame($table->getField('HG')->getType(), Field::TYPE_CHARACTER); | ||
self::assertSame($table->getField('T43')->getType(), Field::TYPE_CHARACTER); | ||
self::assertSame($table->getField('LK')->getType(), Field::TYPE_CHARACTER); | ||
self::assertSame($table->getField('POI')->getType(), Field::TYPE_CHARACTER); | ||
self::assertSame($table->getField('OIU')->getType(), Field::TYPE_CHARACTER); | ||
foreach ($table as $row) { | ||
/** @var Record $row */ | ||
self::assertNotEmpty($row->toArray()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
|
||
namespace org\majkel\dbase\format; | ||
|
||
use org\majkel\dbase\Format; | ||
use org\majkel\dbase\tests\utils\AbstractFormatTest; | ||
use org\majkel\dbase\Field; | ||
|
||
/** | ||
* FoxPro format tests | ||
* | ||
* @author majkel | ||
* | ||
* @coversDefaultClass \org\majkel\dbase\format\FoxPro | ||
*/ | ||
class FoxProTest extends AbstractFormatTest { | ||
|
||
const CLS = '\org\majkel\dbase\format\FoxPro'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getFormatObject() { | ||
return $this->mock(self::CLS)->new(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getSupportedTypes() { | ||
return array( | ||
Field::TYPE_CHARACTER, Field::TYPE_DATE, Field::TYPE_LOGICAL, | ||
Field::TYPE_MEMO, Field::TYPE_NUMERIC | ||
); | ||
} | ||
|
||
/** | ||
* @covers ::createHeader | ||
*/ | ||
public function testCreateHeader() { | ||
$format = $this->getFormatObject(); | ||
$header = $this->reflect($format)->createHeader($this->getHeaderData(array( | ||
'v' => 30, | ||
))); | ||
self::assertTrue($header->isValid()); | ||
} | ||
|
||
/** | ||
* @covers ::createHeader | ||
*/ | ||
public function testCreateHeaderUnknownFormat() { | ||
$format = $this->getFormatObject(); | ||
$header = $this->reflect($format)->createHeader($this->getHeaderData(array( | ||
'v' => 666, | ||
))); | ||
self::assertTrue($header->isValid()); | ||
} | ||
|
||
/** | ||
* @covers ::getName | ||
*/ | ||
public function testGetName() { | ||
self::assertSame('FoxPro', $this->getFormatObject()->getName()); | ||
} | ||
|
||
/** | ||
* @covers ::getType | ||
*/ | ||
public function testGetType() { | ||
self::assertSame(Format::FOXPRO, $this->getFormatObject()->getType()); | ||
} | ||
|
||
} |