Skip to content

Commit 2126dbc

Browse files
committed
Basic test for Rules translator
1 parent 8531b85 commit 2126dbc

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

src/Translators/Rules.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static function fromColumn(Column $column)
1919
// modifiers (unsigned, nullable, unique)
2020

2121
// hack for tests...
22-
if (in_array($column->dataType(), ['string', 'longText'])) {
22+
if (in_array($column->dataType(), ['string', 'char', 'text', 'longText'])) {
2323
$rules = array_merge($rules, ['string']);
2424
}
2525

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
namespace Tests\Feature\Translators;
4+
5+
use Blueprint\Column;
6+
use Blueprint\Translators\Rules;
7+
use Tests\TestCase;
8+
9+
class RulesTest extends TestCase
10+
{
11+
/**
12+
* @test
13+
*/
14+
public function forColumn_returns_required_rule_by_default()
15+
{
16+
$column = new Column('test', 'unknown');
17+
18+
$this->assertEquals(['required'], Rules::fromColumn($column));
19+
}
20+
21+
/**
22+
* @test
23+
* @dataProvider stringDataTypesProvider
24+
*/
25+
public function forColumn_returns_string_rule_for_string_data_types($data_type)
26+
{
27+
$column = new Column('test', $data_type);
28+
29+
$this->assertContains('string', Rules::fromColumn($column));
30+
}
31+
32+
/**
33+
* @test
34+
*/
35+
public function forColumn_returns_max_rule_for_string_attributes()
36+
{
37+
$column = new Column('test', 'string', [], [1000]);
38+
39+
$this->assertContains('max:1000', Rules::fromColumn($column));
40+
41+
$column = new Column('test', 'char', [], [10]);
42+
43+
$this->assertContains('max:10', Rules::fromColumn($column));
44+
}
45+
46+
public function stringDataTypesProvider()
47+
{
48+
return [
49+
['string'],
50+
['char'],
51+
['text']
52+
];
53+
}
54+
55+
}

0 commit comments

Comments
 (0)