diff --git a/.gitea/workflows/demo.yaml b/.gitea/workflows/demo.yaml deleted file mode 100644 index 7edbde4..0000000 --- a/.gitea/workflows/demo.yaml +++ /dev/null @@ -1,19 +0,0 @@ -name: Gitea Actions Demo -run-name: ${{ gitea.actor }} is testing out Gitea Actions -on: [push] - -jobs: - Explore-Gitea-Actions: - runs-on: ubuntu-latest - steps: - - run: echo "🎉 The job was automatically triggered by a ${{ gitea.event_name }} event." - - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by Gitea!" - - run: echo "🔎 The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}." - - name: Check out repository code - uses: actions/checkout@v3 - - run: echo "💡 The ${{ gitea.repository }} repository has been cloned to the runner." - - run: echo "The workflow is now ready to test your code on the runner." - - name: List files in the repository - run: | - ls ${{ gitea.workspace }} - - run: echo "🍏 This job's status is ${{ job.status }}." diff --git a/.gitea/workflows/test.yaml b/.gitea/workflows/test.yaml index f9068b8..7e3fdbd 100644 --- a/.gitea/workflows/test.yaml +++ b/.gitea/workflows/test.yaml @@ -1,13 +1,66 @@ -name: 'Test new actor runner 1.0' +name: 'Test new actor runner 1.1' on: [push] jobs: test: runs-on: ubuntu-latest name: Test + env: + extensions: gd, sqlite3 + php-version: '8.2' + key: cache-v1 # can be any string, change to clear the extension cache. steps: - uses: actions/checkout@v3 - - uses: apoloz/laravel-test-runner@v1.1.13 + + - name: Setup cache environment + id: extcache + uses: apoloz/cache-extensions@v1 with: - php-version: 8.2 - setup: 'true' \ No newline at end of file + php-version: ${{ php-version }} + extensions: ${{ env.extensions }} + key: ${{ env.key }} + + - name: Cache extensions + uses: actions/cache@v3 + with: + path: ${{ steps.extcache.outputs.dir }} + key: ${{ steps.extcache.outputs.key }} + restore-keys: ${{ steps.extcache.outputs.key }} + + - name: Setup PHP + uses: apoloz/setup-php@v2 + with: + php-version: ${{ php-version }} + extensions: ${{ env.extensions }} + coverage: none + + - name: Get composer cache directory + id: composer-cache + run: | + echo "dir=$(composer config cache-files-dir)" + echo "ls -la" + echo "composerhash=$(md5sum composer.lock|awk '{print $1}')" >> $GITHUB_OUTPUT + echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: Cache composer dependencies + uses: actions/cache@v3 + with: + path: ${{ steps.composer-cache.outputs.dir }} + # Use composer.json for key, if composer.lock is not committed. + # key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + key: ${{ runner.os }}-composer-${{ steps.composer-cache.outputs.composerhash }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install composer dependencies + env: + COMPOSER_AUTH: '{"github-oauth": {"github.com": "${{ vars.GH_KEY }}"} }' + run: composer install + + - name: Run test + run: vendor/bin/phpunit + + # - name: Run Pint + # run: vendor/bin/pint + # + # - name: Run Static Analysis + # run: composer static-analysis diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index a346b78..b112279 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -16,7 +16,7 @@ class DatabaseSeeder extends Seeder { $this->call(PlanSeeder::class); $this->call(UserSeeder::class); - $this->call(RecipeSeeder::class); + // $this->call(RecipeSeeder::class); // \App\Models\User::factory(10)->create(); } } diff --git a/database/seeders/RecipeSeeder.php b/database/seeders/RecipeSeeder.php deleted file mode 100644 index 5120977..0000000 --- a/database/seeders/RecipeSeeder.php +++ /dev/null @@ -1,72 +0,0 @@ -image = $this->downloadRandomImage(); - $recipe->state = 'active'; - $recipe->type = $faker->randomElement(['first_meals', 'second_meals', 'salads', 'snacks', 'drinks', 'other']); - $recipe->title = $faker->sentence(5); - $recipe->video_url = $faker->url; - $recipe->cooking_time = $faker->randomElement([10,20,30,60,120,14400]); - $recipe->description = $faker->text(200); - $recipe->steps = [ - ['image' => $this->downloadRandomImage(), 'description' => $faker->text(100)], - ['image' => $this->downloadRandomImage(), 'description' => $faker->text(100)], - ['image' => $this->downloadRandomImage(), 'description' => $faker->text(100)] - ]; - $recipe->ingredients = [ - ['name' => $faker->word, 'portion' => $faker->numberBetween(1, 20), 'unit' => $faker->randomElement(['teespoon', 'tablespoon', 'ml', 'pcs', 'clove', 'to_taste'])], - ['name' => $faker->word, 'portion' => $faker->numberBetween(1, 20), 'unit' => $faker->randomElement(['teespoon', 'tablespoon', 'ml', 'pcs', 'clove', 'to_taste'])], - ['name' => $faker->word, 'portion' => $faker->numberBetween(1, 20), 'unit' => $faker->randomElement(['teespoon', 'tablespoon', 'ml', 'pcs', 'clove', 'to_taste'])], - ]; - $recipe->save(); - for ($j = 0; $j < 10; $j++) { - $comment = new RecipeComment(); - $comment->user_id = User::inRandomOrder()->first()->id; - $comment->recipe_id = $recipe->id; - $comment->grade = $faker->randomElement([1,2,3,4,5]); - $comment->body = $faker->text(100); - $comment->save(); - } - User::inRandomOrder()->first()->author_of_recipe()->attach($recipe->id); - } - - - } - public function downloadRandomImage(): string - { - $faker = FakerFactory::create(); - $url = $faker->imageUrl(640, 480, 'food', true); - $contents = file_get_contents($url); - $dir_path = storage_path('app/public/recipe'); - $path = 'recipe/' . uniqid() . '.jpg'; - if (!file_exists( $dir_path)) { - mkdir( $dir_path, 0777, true); - } - file_put_contents(storage_path('app/public/' . $path), $contents); - - return $path; - } -} diff --git a/tests/Feature/Recipe/EditTest.php b/tests/Feature/Recipe/EditTest.php deleted file mode 100644 index 8978f9c..0000000 --- a/tests/Feature/Recipe/EditTest.php +++ /dev/null @@ -1,105 +0,0 @@ -create(); - $recipe = Recipe::factory()->create([ - 'steps' => [], - 'ingredients' => [], - ]); - $tag1 = Tag::factory()->create(); - $tag2 = Tag::factory()->create(); - - $title = $faker->sentence(3); - $description = $faker->paragraph(2); - $cooking_time = $faker->numberBetween(10, 120); - $type = $faker->randomElement(['Main Dish', 'Dessert', 'Appetizer']); - $video_url = $faker->url; - $image = UploadedFile::fake()->image('new_image.jpg'); - $ingredients_names = [$faker->word, $faker->word, $faker->word]; - $ingredients_portions = [$faker->numberBetween(1, 500), $faker->numberBetween(1, 500), $faker->numberBetween(1, 500)]; - $ingredient_units = [$faker->randomElement(['gr', 'ml', 'pcs']), $faker->randomElement(['gr', 'ml', 'pcs']), $faker->randomElement(['gr', 'ml', 'pcs'])]; - - Livewire::actingAs($user) - ->test('recipe.edit', ['recipe' => $recipe]) - ->set('title', $title) - ->set('description', $description) - ->set('cooking_time', $cooking_time) - ->set('type', $type) - ->set('video_url', $video_url) - ->set('image', $image) - ->set('tags', [$tag1->id, $tag2->id]) - ->call('addIngredient') - ->set('ingredients_name.0', $ingredients_names[0]) - ->set('ingredients_portion.0', $ingredients_portions[0]) - ->set('ingredients_unit.0', $ingredient_units[0]) - ->call('addIngredient') - ->set('ingredients_name.1', $ingredients_names[1]) - ->set('ingredients_portion.1', $ingredients_portions[1]) - ->set('ingredients_unit.1', $ingredient_units[1]) - ->call('addIngredient') - ->set('ingredients_name.2', $ingredients_names[2]) - ->set('ingredients_portion.2', $ingredients_portions[2]) - ->set('ingredients_unit.2', $ingredient_units[2]) - ->call('addStep') - ->set('steps.0.description', $faker->paragraph) - ->set('steps.0.image', UploadedFile::fake()->image('new_step_image0.jpg')) - ->call('addStep') - ->set('steps.1.description', $faker->paragraph) - ->set('steps.1.image', UploadedFile::fake()->image('new_step_image1.jpg')) - ->call('addStep') - ->set('steps.2.description', $faker->paragraph) - ->set('steps.2.image', UploadedFile::fake()->image('new_step_image2.jpg')) - ->call('publish'); - - $this->assertDatabaseHas('recipes', [ - 'title' => $title, - 'description' => $description, - 'cooking_time' => $cooking_time, - 'type' => $type, - 'video_url' => $video_url, - 'image' => $image, - 'ingredients_name.0' => $ingredients_names[0], - 'ingredients_portion.0' => $ingredients_portions[0], - 'ingredients_unit.0' => $ingredient_units[0], - 'ingredients_name.1' => $ingredients_names[1], - 'ingredients_portion.1' => $ingredients_portions[1], - 'ingredients_unit.1' => $ingredient_units[1], - 'ingredients_name.2' => $ingredients_names[2], - 'ingredients_portion.2' => $ingredients_portions[2], - 'ingredients_unit.2' => $ingredient_units[2], - ]); - - $this->assertDatabaseHas('tags', [ - 'id' => $tag1->id, - ]); - $this->assertDatabaseHas('tags', [ - 'id' => $tag2->id, - ]); - - Storage::disk('public')->assertExists('recipes/new_image.jpg'); - Storage::disk('public')->assertExists('steps/new_step_image0.jpg'); - Storage::disk('public')->assertExists('steps/new_step_image1.jpg'); - Storage::disk('public')->assertExists('steps/new_step_image2.jpg'); - } -}