Skip to content
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

Split assertions to traits #223

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

Split assertions to traits #223

wants to merge 12 commits into from

Conversation

b1rdex
Copy link

@b1rdex b1rdex commented Apr 17, 2017

No description provided.

@rquadling
Copy link
Contributor

The docblocks for the traits should not contain the all* or nullOr* methods as the traits do not handle them.

@rquadling
Copy link
Contributor

This will also be a major version upgrade due to a drop in support of PHP 5.3.

@rquadling rquadling added this to the 3.0.0 milestone Apr 17, 2017
@b1rdex
Copy link
Author

b1rdex commented Apr 18, 2017

The docblocks for the traits should not contain the all* or nullOr* methods as the traits do not handle them.

Yes, but that's poor maintainability. I defined abstract __callStatic method in traits and I hold to leave magic docblocks with code.

@rquadling
Copy link
Contributor

If the trait docblock is going to retain the __callStatic() handled methods, then the document generator in /bin needs to be updated to automatically create them as that is how they are maintained at the moment.

I would still say that they shouldn't be present at all, but if they are, they need to be auto generated to reduce the maintenance overhead.

@b1rdex
Copy link
Author

b1rdex commented Apr 18, 2017

Oh, I didn't realize they are generated by script. Ok, it would be simplier to bring them back to Assertion class.

@b1rdex
Copy link
Author

b1rdex commented Apr 18, 2017

@rquadling moved them back and removed abstract method.

@rquadling
Copy link
Contributor

Nice.

Can the const's be moved too? I'd go with a renumbering also so use a value that is composed to represent the some logical grouping.

1xxxx = Type related (11xx Array, 12xx Boolean, etc.)
2xxxx = Class related (property, method, etc).
etc.

@b1rdex
Copy link
Author

b1rdex commented Apr 18, 2017 via email

@rquadling
Copy link
Contributor

Ah. Yes. Odd that PHP can have static members, and properties, but not constants. We should have all the things in all the places.

So. Things look good. Dropping support for PHP < 5.4 is fine by me. I've no intention of really supporting something that EOL'd just for the sake of it.

@rquadling
Copy link
Contributor

I think I'd like the traits in their own sub-directory of Assert.

That way the traits are a subordinate of the Assertion class.

@b1rdex
Copy link
Author

b1rdex commented Apr 19, 2017

Ok I moved traits to namespace Assert\Assertion.
The only thing about consts I have on mind — they can be namespace constants and placed along with trait using it. Example:

namespace Assert\Assertion;

const INVALID_SUBCLASS_OF = 29;
const INVALID_CLASS = 105;
const INVALID_INTERFACE = 106;
const INTERFACE_NOT_IMPLEMENTED = 202;

trait ClassTrait
{
}

Then we can use them in trait as follows:
throw static::createException($value, $message, INVALID_SUBCLASS_OF, …

And in other classes:
throw static::createException($value, $message, Assertion\INVALID_SUBCLASS_OF, …

@rquadling
Copy link
Contributor

I like the idea of the traits having their constants locally. Go with the renumbering also. Maybe if you can draw up the renumbering to first. I can review that prior to committing. Good work so far!

@b1rdex
Copy link
Author

b1rdex commented Apr 20, 2017

Moving constants out from Assertion class will break BC and all tests.

@rquadling
Copy link
Contributor

This is going to be a major release as we are dropping support for PHP 5.3.

But namespaced constants vs class constants ... hmmmm.

I'm happy with the BC. An UPGRADE_3.0.md will be needed to tell devs to rename Assertion::CONSTANT to Assertion\CONSTANT.

To maintain BC, pulling the namespaced constants into the Assertion class is also a possibility for 3.0 and then drop them in 4.0. That can be done using a fairly simple update to the doc generator or probably better to rename the doc generator to something more generic (updating the composer.json entry for generating the docs and updating the CONTRIBUTING.md)

bump required php version

remove php 5.3 travis

add abstract __callStatic

move docblocks back

move traits to namespace

wip

const links generator

add upgrade notes

split assertions to traits

bump required php version

add abstract __callStatic

remove php 5.3 travis

move docblocks back

move traits to namespace
@b1rdex
Copy link
Author

b1rdex commented Apr 21, 2017

Had some merge/force push bug, now all is fixed.
I didn't renumbered constants, jsut moved them.

@rquadling
Copy link
Contributor

Any chance the scalar assertion could move to its own trait? That way all the assertions are in traits.

MAYBE, a scalar trait uses the boolean, string, number, etc. traits?

I'm really liking the segmentation. Good work!!!

@rquadling
Copy link
Contributor

Renumbering the constants would be a nice touch.

@b1rdex
Copy link
Author

b1rdex commented Apr 26, 2017

OK, I moved scalar out to trait and make it use bool, string and number.
Don't know if it's really good…

Also for renumbering: I'm not sure how to do that best, so I leave it for somebody else.

@rquadling
Copy link
Contributor

The unit tests need to have the corrected class constant.

You should be able to use the regular expression Assertion::(?=[A-Z]) to locate all occurrences of the deprecated constants, and replace them with Assertion\.

@rquadling
Copy link
Contributor

Can you also update the UPGRADE_3.0.md doc to use that regex as the one you have will replace all the static calls also.

@rquadling
Copy link
Contributor

Also, take a read of https://thephp.cc/news/2016/02/questioning-phpunit-best-practices regarding the unit tests.

@b1rdex
Copy link
Author

b1rdex commented Apr 27, 2017

Done.

@rquadling
Copy link
Contributor

Care to split the unit tests into 1 file per trait?

@b1rdex
Copy link
Author

b1rdex commented May 2, 2017

Done.

@rquadling
Copy link
Contributor

Excellent!!! Final review tomorrow!! Hopefully.

/**
* @covers \Assert\Assertion\ArrayTrait
*/
class ArrayTraitTest extends \PHPUnit_Framework_TestCase
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use PHPUnit\Framework\TestCase instead of PHPUnit_Framework_TestCase as #238

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carusogabriel I have no time for this. You are free to open PR against my fork.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gonna do it so 👍

@b1rdex
Copy link
Author

b1rdex commented Dec 14, 2017 via email

@b1rdex
Copy link
Author

b1rdex commented Dec 15, 2017

@carusogabriel you broke the tests 🤔 see https://travis-ci.org/beberlei/assert/builds/316258002?utm_source=github_status&utm_medium=notification for details.

/**
* @covers \Assert\Assertion\CallableTrait
*/
class CallableTraitTest extends TestCase
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@b1rdex Forget to use PHPUnit\Framework\TestCase here. I'm sorry

/**
* @covers \Assert\Assertion\ClassTrait
*/
class ClassTraitTest extends TestCase
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@b1rdex Forget to use PHPUnit\Framework\TestCase here. I'm sorry

/**
* @covers \Assert\Assertion\CompareTrait
*/
class CompareTraitTest extends TestCase
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@b1rdex Forget to use PHPUnit\Framework\TestCase here. I'm sorry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants