GithubHelp home page GithubHelp logo

test-laravel-routes's Introduction

Test Your Laravel Routing Skills

This repository is a test for you: fill in routes/web.php and routes/api.php which are left intentionally empty.

In both of those files, you will find comments, describing 12 tasks. For majority of the tasks, you need to write ONE line of code.

Example:

// Task 2: point the GET URL "/user/[name]" to the UserController method "show"
// It doesn't use Route Model Binding, it expects $name as a parameter
// Put one code line here below

To test if all the routes work correctly, there are PHPUnit tests in tests/Feature/RoutesTest.php file.

In the very beginning, if you run php artisan test, or vendor/bin/phpunit, all 8 tests fail. Your task is to make those tests pass.

How to Submit Your Solution

If you want to submit your solution, you should make a Pull Request to the main branch. It will automatically run the tests via Github Actions and will show you/me if the test pass.

If you don't know how to make a Pull Request, here's my video with instructions.

This task is mostly self-served, so I'm not planning review or merge the Pull Requests. This test is for yourselves to assess your skills, the automated tests will be your answer if you passed the test :)

Questions / Problems?

If you're struggling with some of the tasks, or you have suggestions how to improve the task, create a Github Issue.

Good luck!

test-laravel-routes's People

Contributors

krekas avatar povilaskorop avatar thinkverse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

test-laravel-routes's Issues

Hi, I'm still stacked here.

when performing a pull request, the testing is not performed, I have this text:
"1 workflow awaiting approval
First-time contributors need a maintainer to approve running workflows."

Minor issue.

@PovilasKorop , i have found one issue, its a minor but i think it will create issue on system like Linux.

image

The directory name V1 is in caps while in route instructions it is in small case.

facing not found

Hi, where I'm wrong

Route::get('pages/about',function () {
  return view('about');
})->name(name:'about');

I'm facing just 404

9 test

There was 1 failure:

  1. Tests\Feature\RoutesTest::test_is_admin_middleware_is_working
    Expected response status code [201, 301, 302, 303, 307, 308] but received 500.

The following exception occurred during the request:

ErrorException: Attempt to read property "is_admin" on null in /home/runner/work/Test-Laravel-Routes/Test-Laravel-Routes/app/Http/Middleware/IsAdminMiddleware.php:19

Route::middleware('is_admin')->prefix('admin')->group(function () {
..................
}

Execute tests (Unit and Feature tests) via PHPUnit

Run vendor/bin/phpunit
PHPUnit 10.0.9 by Sebastian Bergmann and contributors.

Runtime: PHP 8.1.2-1ubuntu2.14
Configuration: /home/runner/work/Test-Laravel-Routes/Test-Laravel-Routes/phpunit.xml

......F. 8 / 8 (100%)

Time: 00:00.525, Memory: 40.50 MB

There was 1 failure:

  1. Tests\Feature\RoutesTest::test_task_api_crud_is_working
    Expected response status code [200] but received 404.
    Failed asserting that 200 is identical to 404.

/home/runner/work/Test-Laravel-Routes/Test-Laravel-Routes/vendor/laravel/framework/src/Illuminate/Testing/TestResponse.php:123
/home/runner/work/Test-Laravel-Routes/Test-Laravel-Routes/vendor/laravel/framework/src/Illuminate/Testing/Concerns/AssertsStatusCodes.php:16
/home/runner/work/Test-Laravel-Routes/Test-Laravel-Routes/tests/Feature/RoutesTest.php:83
/home/runner/work/Test-Laravel-Routes/Test-Laravel-Routes/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestCase.php:173

FAILURES!
Tests: 8, Assertions: 29, Failures: 1.
Error: Process completed with exit code 1.

Potential spelling mistake

Looking through the routes/web.php file on the line 66 it shows /app however I believe that this should be /admin

// Task 9: /admin group within a group
// Add a group for routes with URL prefix "admin"
// Assign middleware called "is_admin" to them
// Put one Route Group code line here below
// Tasks inside that /app group:

I would put in a PR to change this, however I have already created one for the challenge in hand.

Task 12 doesn't pass (because of wrong Controller)

This is for the ones (like I was) that finished all tasks but the final one (12). It took me about 40mins to figure this out.

Solution: watch carefully the app\Http\Controllers folder. There is a special one called Api.

Test Failed - is_admin middleware called on null

Getting this issue while tests are carried out. Following is the line of codes that I have written for Task 11.

Route::group(['prefix' => 'admin', 'middleware' => 'is_admin'], function () {
Route::get('/dashboard', AdminDashboardController::class);
Route::get('/stats', DashboardController::class);
});

Let me know if anything is wrong with my code or something is wrong with the test case.

Generate Key error

I completed the 12 tasks and passed all tests, however when submitting the pull request, it fails. It gives the indication that it is because of the "Generate Key". (I attach a print). I don´t know what´s going on.

Screenshot 2023-04-06 at 12 40 37

Exception "Route [dashboard] not defined" throws

I am facing bellow exception when trying to reach about page although route has been set correctly :

Route [dashboard] not defined. (View: /home/xristos/tutorials/laravel-daily/test-your-skills/Test-Laravel-Routes/resources/views/layouts/navigation.blade.php)

When does Route [dashboard] should be installed? Is it a Breeze route maybe ?
I tried to install Breeze at beginning but it overwrites web.php files

Tests\Feature\RoutesTest::test_is_admin_middleware_is_working && Tests\Feature\RoutesTest::test_task_api_crud_is_working

  1. Tests\Feature\RoutesTest::test_task_api_crud_is_working
    Expected response status code [200] but received 404.
    Failed asserting that 200 is identical to 404.

  2. Tests\Feature\RoutesTest::test_is_admin_middleware_is_working
    Expected response status code [403] but received 500.
    Failed asserting that 403 is identical to 500.

I have a two errors and this is a code of me :

  1. Route::prefix('app')->group(function(){
    // Tasks inside that /app group:

    // Task 7: point URL /app/dashboard to a "Single Action" DashboardController
    // Assign the route name "dashboard"
    // Put one Route Group code line here below
    
    
    Route::get('dashboard', [DashboardController::class])->name('dashboard');
    // Task 8: Manage tasks with URL /app/tasks/***.
    // Add ONE line to assign 7 resource routes to TaskController
    // Put one code line here below
    
    Route::resource('tasks', TaskController::class);
    

    // End of the /app Route Group

    });

  2. Route::group(['prefix' => 'admin', 'middleware' => ['is_admin']], function(){
    // Tasks inside that /admin group:

    // Task 10: point URL /admin/dashboard to a "Single Action" Admin/DashboardController
    // Put one code line here below

    Route::get('dashboard', [AdminDashboardController::class]);
    // Task 11: point URL /admin/stats to a "Single Action" Admin/StatsController
    // Put one code line here below

    Route::get('stats', [StatsController::class]);
    // End of the /admin Route Group

});

Getting error : Another route has already been assigned name

I have created two routes with respective api and web:

// Task 12: Manage tasks with endpoint /api/v1/tasks/*****.
    // Keep in mind that prefix should be /api/v1.
    // Add ONE line to assign 5 resource routes to TaskController
    // Put one code line here below

Route::apiResource('tasks', TaskController::class);

// Task 8: Manage tasks with URL /app/tasks/***.
// Add ONE line to assign 7 resource routes to TaskController
// Put one code line here below

Route::resource('tasks', TaskController::class);

both are calling different controller, but it gives me error that ( i have already added prefix api/v1 for api route )

Unable to prepare route [app/tasks] for serialization. Another route has already been assigned name [tasks.index].

How to handle this?

Test for Task 4

This task doesn't have a test case, so even I finished the other task, the tests will succeed.

// Task 4: redirect the GET URL "log-in" to a URL "login"
// Put one code line here below

I added the test for this task in #100.

Thank you for all the wisdom you shared

answer

where can I find answers for test to make all all fail correct ?
Because any difference may lead to failure

My pull request did not perform the test

Hello,

I followed the steps in the video to do the fork and then the merge request but when I did the merger request 1599 , the action of running the tests did not execute. Could you help me?

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.