From 52d876c88f205dc01bf9da4148116c2dee995e56 Mon Sep 17 00:00:00 2001 From: PovilasKorop Date: Sun, 5 Dec 2021 13:20:12 +0200 Subject: [PATCH] Task 1 - original filename --- README.md | 68 +++++-------------- app/Http/Controllers/ProjectController.php | 24 +++++++ app/Models/Project.php | 13 ++++ ...021_12_05_110226_create_projects_table.php | 33 +++++++++ routes/web.php | 2 + tests/Feature/ExampleTest.php | 21 ------ tests/Feature/FileUploadTest.php | 31 +++++++++ 7 files changed, 121 insertions(+), 71 deletions(-) create mode 100644 app/Http/Controllers/ProjectController.php create mode 100644 app/Models/Project.php create mode 100644 database/migrations/2021_12_05_110226_create_projects_table.php delete mode 100644 tests/Feature/ExampleTest.php create mode 100644 tests/Feature/FileUploadTest.php diff --git a/README.md b/README.md index 8878ec1..2a2cf93 100644 --- a/README.md +++ b/README.md @@ -1,66 +1,34 @@ -

+## Test Your Laravel File Upload Skills -

-Build Status -Total Downloads -Latest Stable Version -License -

+This repository is a test for you: perform a set of tasks listed below, and fix the PHPUnit tests, which are currently intentionally failing. -## About Laravel +To test if all the functions work correctly, there are PHPUnit tests in `tests/Feature/FileUploadTest.php` file. -Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as: +In the very beginning, if you run `php artisan test`, or `vendor/bin/phpunit`, all tests fail. +Your task is to make those tests pass. -- [Simple, fast routing engine](https://laravel.com/docs/routing). -- [Powerful dependency injection container](https://laravel.com/docs/container). -- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage. -- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent). -- Database agnostic [schema migrations](https://laravel.com/docs/migrations). -- [Robust background job processing](https://laravel.com/docs/queues). -- [Real-time event broadcasting](https://laravel.com/docs/broadcasting). +## How to Submit Your Solution -Laravel is accessible, powerful, and provides tools required for large, robust applications. +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. -## Learning Laravel +If you don't know how to make a Pull Request, [here's my video with instructions](https://www.youtube.com/watch?v=vEcT6JIFji0). -Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework. +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 :) -If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Laracasts contains over 1500 video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library. -## Laravel Sponsors +## Questions / Problems? -We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the Laravel [Patreon page](https://patreon.com/taylorotwell). +If you're struggling with some tasks, or you have suggestions how to improve the task, create a GitHub Issue. -### Premium Partners +Good luck! -- **[Vehikl](https://vehikl.com/)** -- **[Tighten Co.](https://tighten.co)** -- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)** -- **[64 Robots](https://64robots.com)** -- **[Cubet Techno Labs](https://cubettech.com)** -- **[Cyber-Duck](https://cyber-duck.co.uk)** -- **[Many](https://www.many.co.uk)** -- **[Webdock, Fast VPS Hosting](https://www.webdock.io/en)** -- **[DevSquad](https://devsquad.com)** -- **[Curotec](https://www.curotec.com/services/technologies/laravel/)** -- **[OP.GG](https://op.gg)** -- **[CMS Max](https://www.cmsmax.com/)** -- **[WebReinvent](https://webreinvent.com/?utm_source=laravel&utm_medium=github&utm_campaign=patreon-sponsors)** -- **[Lendio](https://lendio.com)** -- **[Romega Software](https://romegasoftware.com)** +--- -## Contributing +## Task 1. Original Filename. -Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions). +In `app/Http/Controllers/ProjectController.php` file, in the `store()` method, get the original filename, to later save it to the DB. -## Code of Conduct +Test method `test_original_filename_upload()`. -In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct). - -## Security Vulnerabilities - -If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [taylor@laravel.com](mailto:taylor@laravel.com). All security vulnerabilities will be promptly addressed. - -## License - -The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT). +--- diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php new file mode 100644 index 0000000..11ce43c --- /dev/null +++ b/app/Http/Controllers/ProjectController.php @@ -0,0 +1,24 @@ +file('logo')->storeAs('logos', $filename); + + Project::create([ + 'name' => $request->name, + 'logo' => $filename, + ]); + + return 'Success'; + } +} diff --git a/app/Models/Project.php b/app/Models/Project.php new file mode 100644 index 0000000..ab38223 --- /dev/null +++ b/app/Models/Project.php @@ -0,0 +1,13 @@ +id(); + $table->string('name'); + $table->string('logo'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('projects'); + } +} diff --git a/routes/web.php b/routes/web.php index b130397..7e82fc6 100644 --- a/routes/web.php +++ b/routes/web.php @@ -16,3 +16,5 @@ use Illuminate\Support\Facades\Route; Route::get('/', function () { return view('welcome'); }); + +Route::post('projects', [\App\Http\Controllers\ProjectController::class, 'store']); diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php deleted file mode 100644 index 4ae02bc..0000000 --- a/tests/Feature/ExampleTest.php +++ /dev/null @@ -1,21 +0,0 @@ -get('/'); - - $response->assertStatus(200); - } -} diff --git a/tests/Feature/FileUploadTest.php b/tests/Feature/FileUploadTest.php new file mode 100644 index 0000000..b0b8cec --- /dev/null +++ b/tests/Feature/FileUploadTest.php @@ -0,0 +1,31 @@ +post('projects', [ + 'name' => 'Some name', + 'logo' => UploadedFile::fake()->image($filename) + ]); + + $response->assertStatus(200); + $this->assertDatabaseHas('projects', [ + 'name' => 'Some name', + 'logo' => $filename + ]); + } +}