pimski

pimski

Member Since 1 Year Ago

Experience Points 41,970
Experience
Level
Lessons Completed 417
Lessons
Completed
Best Reply Awards 0
Best Answer
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • Chatty Cathy Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

06 Jul
4 months ago

pimski left a reply on How Do You Test Database Notifications?

@Nash I understood that, and got my test working, so thanks for that! I was just wondering if code like this is never possible:

$user->notify(new MyDatabaseNotification());
$this->assertCount(1, $user->notifications);

To me this feels more natural. But maybe I just need to change my test-mindset

pimski left a reply on How Do You Test Database Notifications?

Aha. So the way to check a notification is by using the Notification facade? And not by checking the notifications relationship on the user? Even if you don't use Notification::fake() in your test...

pimski left a reply on How Do You Test Database Notifications?

Hi @Nash thanks for the reply. I already managed to test there 'is' a notification. However, my next step was to check the contents of the notification (as stored in the database). And this is what isn't working.

The posted code does work when I check it in the browser. So my guess there is some test-magic going on that prevents the notification from actually being saved in the database. How can one actually save notifications in the database in tests?

pimski left a reply on How Do You Test Database Notifications?

Why? User is standard and the notification is generated with the artisan command "make:notification"

I did change the via method to:

public function via($notifiable)
    {
        return ['database'];
    }

pimski started a new conversation How Do You Test Database Notifications?

Hi there,

How do you test database notifications? The following piece of code works when running in the browser, but gives no results when running in a test case:

auth()->user()->notify(new \App\Notifications\ExportFinished);
dd(\DB::table('notifications')->select()->get()); // empty result set in test

Is the test 'mocking' the notification? I'm not calling Notification::fake(); in my test!

18 Aug
1 year ago

pimski started a new conversation AssertSee + Escaped Output

Hi there,

Sometimes I get a test failure when text can't be found (with assertSee) because it contains escaped characters.

For example the name O'Keefe Group becomes O'Keefe Group in the output. This causes the following assertion to fail:

assertSee(`O'Keefe Group`);

Should I escape my assertions (assertSee/assertSeeText) or is there an easier way?

08 Jun
1 year ago

pimski left a reply on Set Auto Increment Values Before Running Tests?

Thanks for the reply. Though not exactly what I'm looking for, because I don't have the instance in my test function.

pimski left a reply on Set Auto Increment Values Before Running Tests?

I'm using an in memory sqlite database and ran a single test, so I don't think I can have a cleaner starting situation...

pimski started a new conversation Set Auto Increment Values Before Running Tests?

Hi there,

Is it possible to set the auto increment value of a table before running a test (in setUp for example). So something like this:

protected function setUp() {
  parent:setUp();
  setAutoIncrement('products', 1000); // result: ALTER TABLE products AUTO_INCREMENT=1000;
}

Reason: I used a wrong class in my code to check the existence of a record. However, because the other table contained a record with the same id, the test succeeded. It would be nice to set different start numbers for auto increment columns to prevent this situation.

03 Mar
1 year ago

pimski left a reply on Best Way To Juggle With Date Formats?

Hi @5pArxz thanks for your reply!

This is definitely usefull for displaying dates. However, I was wondering if my strategy of collecting/converting dates from a user is the way to go. Or whether there's a cleaner method...

pimski started a new conversation Best Way To Juggle With Date Formats?

Hi there,

I have a Model that has a date attribute (let's call it date :). In the database this is stored as "yyyy-mm-dd". However, in the front-end I want to display the date (and use it in forms) as "dd-mm-yyyy". What's the best way to handle dates?

So far I've found:

  1. Laravel can automatically convert dates to Carbon objects using the $dates array from the HasAttributes trait
  2. You can create a setAttribute() mutator function to process an incoming value before it is set on the $attributes array
  3. If you want to display the date (or use it in a form) you can use the Carbon/DateTime functions

Piece of model code:

protected $dates = ['date'];

public function setDateAttribute($value)
{
    if ($value instanceof Carbon) {
        $this->attributes['date'] = $value;
    } elseif ($value) {
        $this->attributes['date'] = Carbon::createFromFormat('d-m-Y', $value);
    }
}