View | Details | Raw Unified | Return to bug 29857
Collapse All | Expand All

(-)a/t/Koha/Exceptions.t (-2 / +62 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 9;
20
use Test::More tests => 10;
21
use Test::MockObject;
21
use Test::MockObject;
22
use Test::Exception;
22
use Test::Exception;
23
23
Lines 336-338 subtest 'Koha::Exceptions::Plugin tests' => sub { Link Here
336
    # stringify the exception
336
    # stringify the exception
337
    is( "$@", "Calling 'upgrade' died for plugin $plugin_class", 'Exception stringified correctly' );
337
    is( "$@", "Calling 'upgrade' died for plugin $plugin_class", 'Exception stringified correctly' );
338
};
338
};
339
- 
339
340
subtest 'Koha::Exception tests' => sub {
341
342
    plan tests => 8;
343
344
    use Koha::Exception;
345
346
    use Exception::Class (
347
        'Koha::Exceptions::Weird' => {
348
            isa         => 'Koha::Exception',
349
            description => 'Weird exception!',
350
            fields      => [ 'a', 'b' ]
351
        }
352
    );
353
354
    my $exception_message = "This is a message";
355
356
    throws_ok
357
        { Koha::Exceptions::Weird->throw( $exception_message ) }
358
        'Koha::Exception',
359
        'Exception is thrown :-D';
360
361
    is(
362
        "$@",
363
        "Exception 'Koha::Exceptions::Weird' thrown '$exception_message'\n",
364
        'Exception not stringified if manually passed'
365
    );
366
367
    throws_ok
368
        { Koha::Exceptions::Weird->throw( a => "A", b => "B" ) }
369
        'Koha::Exception',
370
        'Exception is thrown :-D';
371
372
    is(
373
        "$@",
374
        "Exception 'Koha::Exceptions::Weird' thrown 'Weird exception!' with a => A, b => B\n",
375
        'Exception stringified correctly'
376
    );
377
378
    throws_ok
379
        { Koha::Exceptions::Weird->throw( a => "A" ) }
380
        'Koha::Exception',
381
        'Exception is thrown :-D';
382
383
    is(
384
        "$@",
385
        "Exception 'Koha::Exceptions::Weird' thrown 'Weird exception!' with a => A\n",
386
        'Exception stringified correctly, b skipped entirely'
387
    );
388
389
    throws_ok
390
        { Koha::Exceptions::Weird->throw() }
391
        'Koha::Exception',
392
        'Exception is thrown :-D';
393
394
    is(
395
        "$@",
396
        "Exception 'Koha::Exceptions::Weird' thrown 'Weird exception!'\n",
397
        'Exception stringified correctly'
398
    );
399
};

Return to bug 29857