Add isBase flag on Currency

This commit is contained in:
Magdalena Banasiak 2016-01-12 15:10:58 +01:00
parent 2ecfcea49b
commit 5643e94399
6 changed files with 78 additions and 0 deletions

View file

@ -0,0 +1,34 @@
<?php
namespace Sylius\Migrations;
use Doctrine\DBAL\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema;
/**
* Auto-generated Migration: Please modify to your needs!
*/
class Version20160112145643 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE sylius_currency ADD base TINYINT(1) NOT NULL');
}
/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.');
$this->addSql('ALTER TABLE sylius_currency DROP base');
}
}

View file

@ -23,6 +23,7 @@
<field fieldName="code" name="code" type="string" length="3" />
<field fieldName="exchangeRate" name="exchangeRate" type="float" />
<field fieldName="enabled" name="enabled" type="boolean" />
<field name="base" column="base" type="boolean" />
<field fieldName="createdAt" name="createdAt" type="date">
<gedmo:timestampable on="create"/>

View file

@ -25,6 +25,7 @@
<field name="code" column="code" type="string" length="3" unique="true"/>
<field name="exchangeRate" column="exchange_rate" type="decimal" precision="10" scale="5" />
<field name="enabled" column="enabled" type="boolean" />
<field name="base" column="base" type="boolean" />
<field name="createdAt" column="created_at" type="datetime">
<gedmo:timestampable on="create"/>

View file

@ -38,6 +38,11 @@ class Currency implements CurrencyInterface
*/
protected $enabled = true;
/**
* @var bool
*/
protected $base = false;
/**
* @var \DateTime
*/
@ -172,4 +177,20 @@ class Currency implements CurrencyInterface
{
$this->enabled = false;
}
/**
* {@inheritdoc}
*/
public function isBase()
{
return $this->base;
}
/**
* {@inheritdoc}
*/
public function setBase($base)
{
$this->base = $base;
}
}

View file

@ -41,4 +41,14 @@ interface CurrencyInterface extends
* @param float $rate
*/
public function setExchangeRate($rate);
/**
* @return bool
*/
public function isBase();
/**
* @param bool $base
*/
public function setBase($base);
}

View file

@ -91,6 +91,17 @@ class CurrencySpec extends ObjectBehavior
$this->shouldNotBeEnabled();
}
function it_is_not_base_currency_by_default()
{
$this->shouldNotBeBase();
}
function it_can_can_be_base_currency()
{
$this->setBase(true);
$this->shouldBeBase();
}
function it_initializes_creation_date_by_default()
{
$this->getCreatedAt()->shouldHaveType(\DateTime::class);