Repository navigation
Conversation
Adds a PHPUnit suite for Crud: getUrl, setTabla, setTablaId, setTitulo, setExport, setSearch, setStateSave, setSoftDelete, setResponsive, setPerPage, setTemplate, setPermisos, setSlug, setWhere, setWhereIn, setWhereRaw, setLeftJoin, setGroupBy, setOrderBy, setHidden, setBotonExtra and setCampo. Crud is a static class with no CrudController equivalent here: index, create, store, destroy and getData are all driven by the Input, Request, Session, View, Redirect and DB facades and need a booted Laravel application, so they are left untested. The suite only covers what can be exercised without one: the pure getUrl() helper and the setters that shape the static state, including the branching and defaulting logic inside setCampo(). Static state is reset before every test since it persists across calls. phpunit is require-dev only, so nothing changes for consumers of the package. Run with `composer install && vendor/bin/phpunit`.
The file is already listed in .gitignore and the committed copy was stale: it predated the illuminate/support ~5.1 constraint, so composer install failed on a clean checkout. A library should resolve its dependencies against the host application anyway.
Every setter of this class is static and writes a static property, and the facade is used as `Crud::setX(...)`. `setResponsive()` was declared without the `static` keyword while still writing `self::$responsive`, so the documented call `Crud::setResponsive(false)` was a fatal error and the option could only be reached through an instance. Adding the keyword makes the static call work and keeps any existing instance call working, since a static method can still be called on an instance.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Crud.Why
The
composer.jsonconstraints across the repo are stale, so there was noreliable way to tell which branch to install for a given Laravel version. On
this branch specifically, the committed
composer.lockpredated theilluminate/support ~5.1constraint, socomposer installfailed outright ona clean checkout.
composer.lockis already listed in.gitignore, and alibrary should resolve its dependencies against the host application anyway.
Scope of the tests
Covered:
getUrland the static setters —setTabla,setTablaId,setTitulo,setExport,setSearch,setStateSave,setSoftDelete,setResponsive,setPerPage,setTemplate,setPermisos,setSlug,setWhere(both arities),setWhereIn,setWhereRaw,setLeftJoin,setGroupBy,setOrderBy,setHidden,setBotonExtra, andsetCampoacrossits branches.
Not covered, and why:
index(),create(),store(),destroy()andgetData()depend on theInput,Request,Session,View,RedirectandDBfacades plus a booted application, which cannot be exercised withouteffectively starting Laravel. The
dd()-guarded validation branches are alsoleft out, since calling them terminates the PHPUnit process.
composer install && vendor/bin/phpunit— 21 tests, 53 assertions, green.Note
This branch is archived: the listing optimization applied to
5.3and up wasnot backported here, and its API is the old static
Crudfacade rather thanCrudController.