pimski

Experience

36,570

0 Best Reply Awards

  • Member Since 1 Year Ago
  • 363 Lessons Completed
  • 0 Favorites

6th July, 2018

pimski left a reply on How Do You Test Database Notifications? • 1 week ago

@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? • 1 week ago

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? • 1 week ago

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? • 2 weeks ago

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? • 2 weeks ago

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!

18th August, 2017

pimski started a new conversation AssertSee + Escaped Output • 11 months ago

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?

8th June, 2017

pimski left a reply on Set Auto Increment Values Before Running Tests? • 1 year ago

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? • 1 year ago

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? • 1 year ago

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.

3rd March, 2017

pimski left a reply on Best Way To Juggle With Date Formats? • 1 year ago

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? • 1 year ago

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);
    }
}
Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.