nathggns / Scaffold

Lightweight PHP API Framework
Other
8 stars 2 forks source link

Should be able to name the various tests for a value in a validator. #111

Closed nathggns closed 11 years ago

nathggns commented 11 years ago

It's possible to pass an array of tests for a value to the validator, but if you name them (passing a key), they just don't get called.

Instead, they should be named. This is especially useful for closure tests.

In the exception that is thrown, the name would be this passed name.

ClaudioAlbertin commented 11 years ago

Do you have an example?

nathggns commented 11 years ago

So far example, on a user model, you added a test to make sure that a username doesn't already exist, that would have to be a closure.

You'd want it the rules array to be something like this.

[
    'username' => [
        'username_exists' => function($username) {
            // ...
        }
    ]
]

And if that fails, you'd want to be able to get the username_exists as the name, as that's significant. The instance of closure, is not.

Right now, that just won't run as a test.

nathggns commented 11 years ago

f68e1dacda6ce6abb5e9eafb35ce635bcdd79cdc implements this. What do you think @ClaudioAlbertin?

nathggns commented 11 years ago

Been a while now. What do you think @ClaudioAlbertin?

ClaudioAlbertin commented 11 years ago

Does it work without giving tests a name? If yes, it should be fine.

nathggns commented 11 years ago

I wrote the code a while ago but I think so. Check the validator tests in this branch.  — Nathaniel Higgins http://nath.is

On Sat, Jun 1, 2013 at 11:13 PM, Claudio Albertin notifications@github.com wrote:

Does it work without giving tests a name? If yes, it should be fine.

Reply to this email directly or view it on GitHub: https://github.com/Scaffold/Scaffold/issues/111#issuecomment-18797988

ClaudioAlbertin commented 11 years ago

Should be fine then.

nathggns commented 11 years ago

I'll merge it tomorrow then. — Nathaniel Higgins http://nath.is

On Sat, Jun 1, 2013 at 11:19 PM, Claudio Albertin notifications@github.com wrote:

Should be fine then.

Reply to this email directly or view it on GitHub: https://github.com/Scaffold/Scaffold/issues/111#issuecomment-18798083