test: add WordPress fixtures and route coverage - #6
Open
Guajir0-code wants to merge 1 commit into
Open
Conversation
The app points Eloquent at an existing WordPress database, so no migration creates wp_posts, wp_users, wp_terms and friends. Any test that touched the database therefore could not run, and the single feature test in the repo (GET / asserting 200) failed on a missing database. Add a schema builder for the wp_* tables the app reads, small row builders, and smoke coverage for all seven routes in routes/web.php, including the highlighted-post exclusion, search, and the published/scheduled filtering the global scope is responsible for. withoutVite() keeps the suite independent of `npm run build`. ExampleTest is dropped: RoutesTest covers GET / properly. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Problema
O projeto não tem cobertura de testes, e não é por falta de vontade: não havia como escrever um teste que tocasse o banco.
Evidência
O único teste de feature do repositório falha:
Corrigido o banco de teste, ele passa a falhar de novo, agora por outro motivo:
A causa é estrutural: este projeto aponta o Eloquent para um WordPress existente, então nenhuma migration cria
wp_posts,wp_users,wp_termse as demais. Sem elas, qualquer teste que chegue ao banco morre na primeira query, e o workflowtestsestá vermelho.Solução
tests/Support/WordPressSchema.phpCria as sete tabelas que a aplicação lê:
wp_posts,wp_postmeta,wp_users,wp_usermeta,wp_terms,wp_term_taxonomy,wp_term_relationships.Os tipos seguem o WordPress de perto o bastante para que as consultas de
App\ModelseApp\Servicesse comportem como em produção. Colunas que a aplicação nunca lê ficaram de fora, de propósito, para o arquivo continuar legível.Vale registrar um efeito colateral útil: como o app não tem migrations para essas tabelas, este arquivo passa a ser o único lugar do repositório onde o schema esperado está descrito.
tests/Support/Wp.phpConstrutores curtos para as linhas:
Wp::user(),Wp::post(),Wp::term(),Wp::categorise(),Wp::thumbnail(),Wp::postMeta(),Wp::userMeta().Não usei factories do Eloquent porque os models
Wp*não declaram$fillablee vários têm chave primária fora da convenção (ID,term_id,meta_id). Inserts diretos ficam mais perto do que o banco de produção realmente contém e evitam configurar o Eloquent para um caso que só existe no teste.tests/Pest.phpwithoutVite()desacopla a suíte denpm run build: sem ele, renderizar a view raiz exige um manifest compilado, e os testes falham numa máquina limpa.O
cache()->flush()importa porque os services cacheiam agressivamente — sem isso um teste vaza resultado para o seguinte.tests/Feature/RoutesTest.phpCobertura das sete rotas de
routes/web.php, mais os comportamentos que ninguém verificava:destaquesaparecem no carrossel e não na listagem?s=filtra e devolve o termoOs dois últimos são o tipo de coisa que quebra em silêncio: se
WpPostScopeparar de filtrarpost_status, rascunhos vazam para a home e nada avisa.Como validar
php artisan testEsta é a primeira vez que a suíte fica verde no repositório.
Impacto
app/. Este PR só adicionatests/e ajustaphpunit.xml.testspassa a passar. Nenhuma alteração foi necessária notests.yml— comphpunit.xmlcorrigido ewithoutVite(), o workflow existente já funciona.phpunit.xmlDB_DATABASE=testingsemDB_CONNECTIONfazia o sqlite procurar um arquivo chamadotesting. É a mesma alteração presente nos outros PRs desta série; se algum for mesclado antes, esta parte vira no-op.ExampleTestremovidoRoutesTestcobreGET /de forma real, com dados e asserções sobre os props. Manter o stub que só verifica 200 seria redundante.Fora de escopo
WordPressSchemaprecisa acompanhar.