-
-
Notifications
You must be signed in to change notification settings - Fork 31
Boolean comparison #230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Boolean comparison #230
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6153928
style(php-cs-fixer): fix coding standards
a8c3292
Ensures differences in size for boolean columns are ignore when match…
puzzledpolymath 116af09
Merge remote-tracking branch 'origin/boolean-comparison' into boolean…
puzzledpolymath 9c1911f
chore: test without hostfix
roxblnfk 0748d37
Added a test case which proves the issue
puzzledpolymath d7811b8
Added a test case which confirms the issue
puzzledpolymath 4940fcd
Merge remote-tracking branch 'origin/boolean-comparison' into boolean…
puzzledpolymath c53289b
Removed code which should be here
puzzledpolymath 67ec438
Fixes the issue when comparing boolean columns under certain circumst…
puzzledpolymath ac24bf2
Merge branch '2.x' into boolean-comparison
puzzledpolymath f47cdbf
refactor: simplify boolean value handling in default value assignment
roxblnfk 9ac4fb2
Update AbstractColumn.php
puzzledpolymath File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -14,4 +14,76 @@ | |
| class BooleanColumnTest extends CommonClass | ||
| { | ||
| public const DRIVER = 'mysql'; | ||
|
|
||
| public function testBooleanDefaultSize(): void | ||
| { | ||
| $schema = $this->schema('table'); | ||
| $schema->boolean('column'); | ||
| $schema->save(); | ||
|
|
||
| $column = $this->fetchSchema($schema)->column('column'); | ||
|
|
||
| $this->assertSame('boolean', $column->getAbstractType()); | ||
| $this->assertSame(1, $column->getSize()); | ||
| } | ||
|
|
||
| public function testBooleanComparisonWithSize(): void | ||
| { | ||
| $schema = $this->schema('table'); | ||
| $foo = $schema->boolean('foo')->defaultValue(false)->nullable(false)->unsigned(true)->size(1)->zerofill(true); | ||
| $bar = $schema->boolean('bar', nullable: true, unsigned: true, size: 1, zerofill: true); | ||
| $baz = $schema->boolean('baz', nullable: false, unsigned: true); | ||
| $mux = $schema->boolean('mux', nullable: false); | ||
| $schema->save(); | ||
|
|
||
| $schema = $this->schema('table'); | ||
| $this->assertTrue($schema->exists()); | ||
| $this->assertSame(1, $foo->getSize()); | ||
| $this->assertSame(1, $bar->getSize()); | ||
| $this->assertSame(1, $baz->getSize()); | ||
| $this->assertSame(1, $mux->getSize()); | ||
| $this->assertSame(1, $schema->column('foo')->getSize()); | ||
| $this->assertSame(1, $schema->column('bar')->getSize()); | ||
| $this->assertTrue(\in_array($schema->column('baz')->getSize(), [1, 4], true)); | ||
| $this->assertSame(1, $schema->column('mux')->getSize()); | ||
| $this->assertTrue($foo->compare($schema->column('foo'))); | ||
| $this->assertTrue($bar->compare($schema->column('bar'))); | ||
| $this->assertTrue($baz->compare($schema->column('baz'))); | ||
| $this->assertTrue($mux->compare($schema->column('mux'))); | ||
| } | ||
|
|
||
| public function testBooleanWithProblematicValues(): void | ||
| { | ||
| $schema = $this->schema('table'); | ||
|
|
||
| $column = $schema->boolean('target') | ||
| ->defaultValue(false) | ||
| ->nullable(false) | ||
| ->unsigned(true) | ||
| ->comment('Target comment'); | ||
|
|
||
| $schema->save(); | ||
|
|
||
| $this->assertTrue($schema->exists()); | ||
|
|
||
| $schema = $this->schema('table'); | ||
| $target = $schema->column('target'); | ||
|
|
||
| $this->assertSame(1, $column->getSize()); | ||
| $this->assertSame(4, $target->getSize()); | ||
| $this->assertFalse($column->isNullable()); | ||
| $this->assertFalse($target->isNullable()); | ||
| $this->assertTrue($column->isUnsigned()); | ||
| $this->assertTrue($target->isUnsigned()); | ||
|
|
||
| $object = new \ReflectionObject($target); | ||
| $property = $object->getProperty('defaultValue'); | ||
| $property->setAccessible(true); | ||
| $defaultValue = $property->getValue($target); | ||
|
|
||
| $this->assertSame(false, $column->getDefaultValue()); | ||
| $this->assertSame(0, $target->getDefaultValue()); | ||
| $this->assertSame('0', $defaultValue); | ||
| $this->assertTrue($column->compare($target)); | ||
| } | ||
|
Comment on lines
+55
to
+88
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @roxblnfk It took a while! But here is the test case which confirms the issue, under very specific conditions and attributes defined. Having a comment somehow contributes to the problem. |
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.