|
12 | 12 |
|
13 | 13 | namespace chillerlan\DatabaseTest;
|
14 | 14 |
|
15 |
| -use chillerlan\Database\{ |
16 |
| - Database, DatabaseOptions |
17 |
| -}; |
| 15 | +use chillerlan\Database\{Database, DatabaseOptions, Query\QueryException}; |
18 | 16 | use chillerlan\Database\Dialects\{
|
19 | 17 | Dialect, Firebird, MSSQL, MySQL, Postgres, SQLite
|
20 | 18 | };
|
21 | 19 | use chillerlan\Database\Drivers\{
|
22 |
| - DriverInterface, FirebirdPDO, MSSqlSrv, MSSqlSrvPDO, MySQLiDrv, MySQLPDO, PostgreSQL, PostgreSQLPDO, SQLitePDO |
| 20 | + DriverException, DriverInterface, FirebirdPDO, MSSqlSrv, MSSqlSrvPDO, MySQLiDrv, MySQLPDO, PostgreSQL, PostgreSQLPDO, SQLitePDO |
23 | 21 | };
|
24 | 22 | use chillerlan\Database\Query\QueryBuilder;
|
25 | 23 | use chillerlan\DotEnv\DotEnv;
|
@@ -98,7 +96,7 @@ class DatabaseTest extends TestCase{
|
98 | 96 | /**
|
99 | 97 | *
|
100 | 98 | */
|
101 |
| - protected function setUp(){ |
| 99 | + protected function setUp():void{ |
102 | 100 | $this->env = (new DotEnv(__DIR__.'/../config', file_exists(__DIR__.'/../config/.env') ? '.env' : '.env_travis'))->load();
|
103 | 101 |
|
104 | 102 | $this->isCI = $this->env->get('IS_CI') === 'TRUE';
|
@@ -128,7 +126,7 @@ protected function __log(string $level, string $message, array $context = null):
|
128 | 126 | /**
|
129 | 127 | *
|
130 | 128 | */
|
131 |
| - protected function tearDown(){ |
| 129 | + protected function tearDown():void{ |
132 | 130 |
|
133 | 131 | if(isset($this->db) && $this->db instanceof Database){
|
134 | 132 | $this->assertTrue($this->db->disconnect());
|
@@ -592,240 +590,263 @@ public function testShowCreateTable(string $driver, string $env_prefix, bool $sk
|
592 | 590 | // exceptions galore!
|
593 | 591 |
|
594 | 592 | /**
|
595 |
| - * @dataProvider driverProvider |
596 |
| - * @expectedException \chillerlan\Database\Drivers\DriverException |
597 |
| - * @expectedExceptionMessage db error: |
| 593 | + * @dataProvider driverProvider |
598 | 594 | */
|
599 | 595 | public function testConnectError(string $driver, string $env_prefix, bool $skip_on_ci){
|
| 596 | + $this->expectException(DriverException::class); |
| 597 | + $this->expectExceptionMessage('db error:'); |
| 598 | + |
600 | 599 | $this->dbInstance($driver, $env_prefix, $skip_on_ci, ['host' => '...', 'database' => '...']);
|
601 | 600 | }
|
602 | 601 |
|
603 | 602 | /**
|
604 |
| - * @dataProvider driverProvider |
605 |
| - * @expectedException \chillerlan\Database\Query\QueryException |
606 |
| - * @expectedExceptionMessage invalid statement |
| 603 | + * @dataProvider driverProvider |
607 | 604 | */
|
608 | 605 | public function testInvalidStatement(string $driver, string $env_prefix, bool $skip_on_ci){
|
| 606 | + $this->expectException(QueryException::class); |
| 607 | + $this->expectExceptionMessage('invalid statement'); |
| 608 | + |
609 | 609 | $this->dbInstance($driver, $env_prefix, $skip_on_ci);
|
610 | 610 | $this->db->foo;
|
611 | 611 | }
|
612 | 612 |
|
613 | 613 | /**
|
614 |
| - * @dataProvider driverProvider |
615 |
| - * @expectedException \chillerlan\Database\Query\QueryException |
616 |
| - * @expectedExceptionMessage no name specified |
| 614 | + * @dataProvider driverProvider |
617 | 615 | */
|
618 | 616 | public function testCreateDatabaseNoName(string $driver, string $env_prefix, bool $skip_on_ci){
|
| 617 | + $this->expectException(QueryException::class); |
| 618 | + $this->expectExceptionMessage('no name specified'); |
| 619 | + |
619 | 620 | $this->dbInstance($driver, $env_prefix, $skip_on_ci);
|
620 | 621 | $this->db->create->database('')->sql();
|
621 | 622 | }
|
622 | 623 |
|
623 | 624 | /**
|
624 |
| - * @dataProvider driverProvider |
625 |
| - * @expectedException \chillerlan\Database\Query\QueryException |
626 |
| - * @expectedExceptionMessage no name specified |
| 625 | + * @dataProvider driverProvider |
627 | 626 | */
|
628 | 627 | public function testCreateTableNoName(string $driver, string $env_prefix, bool $skip_on_ci){
|
| 628 | + $this->expectException(QueryException::class); |
| 629 | + $this->expectExceptionMessage('no name specified'); |
| 630 | + |
629 | 631 | $this->dbInstance($driver, $env_prefix, $skip_on_ci);
|
630 | 632 | $this->db->create->table('')->sql();
|
631 | 633 | }
|
632 | 634 |
|
633 | 635 | /**
|
634 | 636 | * @dataProvider driverProvider
|
635 |
| - * @expectedException \chillerlan\Database\Query\QueryException |
636 |
| - * @expectedExceptionMessage no name specified |
637 | 637 | */
|
638 | 638 | public function testDropDatabaseNoName(string $driver, string $env_prefix, bool $skip_on_ci){
|
| 639 | + $this->expectException(QueryException::class); |
| 640 | + $this->expectExceptionMessage('no name specified'); |
| 641 | + |
639 | 642 | $this->dbInstance($driver, $env_prefix, $skip_on_ci);
|
640 | 643 | $this->db->drop->database('')->sql();
|
641 | 644 | }
|
642 | 645 |
|
643 | 646 | /**
|
644 | 647 | * @dataProvider driverProvider
|
645 |
| - * @expectedException \chillerlan\Database\Query\QueryException |
646 |
| - * @expectedExceptionMessage no name specified |
647 | 648 | */
|
648 | 649 | public function testDropTableNoName(string $driver, string $env_prefix, bool $skip_on_ci){
|
| 650 | + $this->expectException(QueryException::class); |
| 651 | + $this->expectExceptionMessage('no name specified'); |
| 652 | + |
649 | 653 | $this->dbInstance($driver, $env_prefix, $skip_on_ci);
|
650 | 654 | $this->db->drop->table('')->sql();
|
651 | 655 | }
|
652 | 656 |
|
653 | 657 | /**
|
654 |
| - * @dataProvider driverProvider |
655 |
| - * @expectedException \chillerlan\Database\Query\QueryException |
656 |
| - * @expectedExceptionMessage no name specified |
| 658 | + * @dataProvider driverProvider |
657 | 659 | */
|
658 | 660 | public function testInsertNoTable(string $driver, string $env_prefix, bool $skip_on_ci){
|
| 661 | + $this->expectException(QueryException::class); |
| 662 | + $this->expectExceptionMessage('no name specified'); |
| 663 | + |
659 | 664 | $this->dbInstance($driver, $env_prefix, $skip_on_ci);
|
660 | 665 | $this->db->insert->into('')->sql();
|
661 | 666 | }
|
662 | 667 |
|
663 | 668 | /**
|
664 |
| - * @dataProvider driverProvider |
665 |
| - * @expectedException \chillerlan\Database\Query\QueryException |
666 |
| - * @expectedExceptionMessage no values given |
| 669 | + * @dataProvider driverProvider |
667 | 670 | */
|
668 | 671 | public function testInsertInvalidData(string $driver, string $env_prefix, bool $skip_on_ci){
|
| 672 | + $this->expectException(QueryException::class); |
| 673 | + $this->expectExceptionMessage('no values given'); |
| 674 | + |
669 | 675 | $this->dbInstance($driver, $env_prefix, $skip_on_ci);
|
670 | 676 | $this->db->insert->into('foo')->values([])->sql();
|
671 | 677 | }
|
672 | 678 |
|
673 | 679 | /**
|
674 |
| - * @dataProvider driverProvider |
675 |
| - * @expectedException \chillerlan\Database\Query\QueryException |
676 |
| - * @expectedExceptionMessage no FROM expression specified |
| 680 | + * @dataProvider driverProvider |
677 | 681 | */
|
678 | 682 | public function testSelectEmptyFrom(string $driver, string $env_prefix, bool $skip_on_ci){
|
| 683 | + $this->expectException(QueryException::class); |
| 684 | + $this->expectExceptionMessage('no FROM expression specified'); |
| 685 | + |
679 | 686 | $this->dbInstance($driver, $env_prefix, $skip_on_ci);
|
680 | 687 | $this->db->select->from([])->sql();
|
681 | 688 | }
|
682 | 689 |
|
683 | 690 | /**
|
684 |
| - * @dataProvider driverProvider |
685 |
| - * @expectedException \chillerlan\Database\Query\QueryException |
686 |
| - * @expectedExceptionMessage no name specified |
| 691 | + * @dataProvider driverProvider |
687 | 692 | */
|
688 | 693 | public function testUpdateNoTable(string $driver, string $env_prefix, bool $skip_on_ci){
|
| 694 | + $this->expectException(QueryException::class); |
| 695 | + $this->expectExceptionMessage('no name specified'); |
| 696 | + |
689 | 697 | $this->dbInstance($driver, $env_prefix, $skip_on_ci);
|
690 | 698 | $this->db->update->table('')->sql();
|
691 | 699 | }
|
692 | 700 |
|
693 | 701 | /**
|
694 |
| - * @dataProvider driverProvider |
695 |
| - * @expectedException \chillerlan\Database\Query\QueryException |
696 |
| - * @expectedExceptionMessage no fields to update specified |
| 702 | + * @dataProvider driverProvider |
697 | 703 | */
|
698 | 704 | public function testUpdateNoSet(string $driver, string $env_prefix, bool $skip_on_ci){
|
| 705 | + $this->expectException(QueryException::class); |
| 706 | + $this->expectExceptionMessage('no fields to update specified'); |
| 707 | + |
699 | 708 | $this->dbInstance($driver, $env_prefix, $skip_on_ci);
|
700 | 709 | $this->db->update->table('foo')->set([])->sql();
|
701 | 710 | }
|
702 | 711 |
|
703 | 712 | /**
|
704 |
| - * @dataProvider driverProvider |
705 |
| - * @expectedException \chillerlan\Database\Query\QueryException |
706 |
| - * @expectedExceptionMessage no name specified |
| 713 | + * @dataProvider driverProvider |
707 | 714 | */
|
708 | 715 | public function testDeleteNoTable(string $driver, string $env_prefix, bool $skip_on_ci){
|
| 716 | + $this->expectException(QueryException::class); |
| 717 | + $this->expectExceptionMessage('no name specified'); |
| 718 | + |
709 | 719 | $this->dbInstance($driver, $env_prefix, $skip_on_ci);
|
710 | 720 | $this->db->delete->from('')->sql();
|
711 | 721 | }
|
712 | 722 |
|
713 | 723 | /**
|
714 |
| - * @dataProvider driverProvider |
715 |
| - * @expectedException \chillerlan\Database\Drivers\DriverException |
716 |
| - * @expectedExceptionMessage sql error: empty sql |
| 724 | + * @dataProvider driverProvider |
717 | 725 | */
|
718 | 726 | public function testRawEmptySQL(string $driver, string $env_prefix, bool $skip_on_ci){
|
| 727 | + $this->expectException(DriverException::class); |
| 728 | + $this->expectExceptionMessage('sql error: empty sql'); |
| 729 | + |
719 | 730 | $this->dbInstance($driver, $env_prefix, $skip_on_ci);
|
720 | 731 |
|
721 | 732 | $this->db->raw('');
|
722 | 733 | }
|
723 | 734 |
|
724 | 735 | /**
|
725 |
| - * @dataProvider driverProvider |
726 |
| - * @expectedException \chillerlan\Database\Drivers\DriverException |
727 |
| - * @expectedExceptionMessage sql error: |
| 736 | + * @dataProvider driverProvider |
728 | 737 | */
|
729 | 738 | public function testRawSQLError(string $driver, string $env_prefix, bool $skip_on_ci){
|
| 739 | + $this->expectException(DriverException::class); |
| 740 | + $this->expectExceptionMessage('sql error:'); |
| 741 | + |
730 | 742 | $this->dbInstance($driver, $env_prefix, $skip_on_ci);
|
731 | 743 |
|
732 | 744 | $this->db->raw('SELECT foo bar');
|
733 | 745 | }
|
734 | 746 |
|
735 | 747 | /**
|
736 |
| - * @dataProvider driverProvider |
737 |
| - * @expectedException \chillerlan\Database\Drivers\DriverException |
738 |
| - * @expectedExceptionMessage sql error: empty sql |
| 748 | + * @dataProvider driverProvider |
739 | 749 | */
|
740 | 750 | public function testPreparedEmptySQL(string $driver, string $env_prefix, bool $skip_on_ci){
|
| 751 | + $this->expectException(DriverException::class); |
| 752 | + $this->expectExceptionMessage('sql error: empty sql'); |
| 753 | + |
741 | 754 | $this->dbInstance($driver, $env_prefix, $skip_on_ci);
|
742 | 755 |
|
743 | 756 | $this->db->prepared('');
|
744 | 757 | }
|
745 | 758 |
|
746 | 759 | /**
|
747 |
| - * @dataProvider driverProvider |
748 |
| - * @expectedException \chillerlan\Database\Drivers\DriverException |
749 |
| - * @expectedExceptionMessage sql error: |
| 760 | + * @dataProvider driverProvider |
750 | 761 | */
|
751 | 762 | public function testPreparedSQLError(string $driver, string $env_prefix, bool $skip_on_ci){
|
| 763 | + $this->expectException(DriverException::class); |
| 764 | + $this->expectExceptionMessage('sql error:'); |
| 765 | + |
752 | 766 | $this->dbInstance($driver, $env_prefix, $skip_on_ci);
|
753 | 767 |
|
754 | 768 | $this->db->prepared('SELECT foo bar ???');
|
755 | 769 | }
|
756 | 770 |
|
757 | 771 | /**
|
758 |
| - * @dataProvider driverProvider |
759 |
| - * @expectedException \chillerlan\Database\Drivers\DriverException |
760 |
| - * @expectedExceptionMessage sql error: empty sql |
| 772 | + * @dataProvider driverProvider |
761 | 773 | */
|
762 | 774 | public function testMultiEmptySQL(string $driver, string $env_prefix, bool $skip_on_ci){
|
| 775 | + $this->expectException(DriverException::class); |
| 776 | + $this->expectExceptionMessage('sql error: empty sql'); |
| 777 | + |
763 | 778 | $this->dbInstance($driver, $env_prefix, $skip_on_ci);
|
764 | 779 |
|
765 | 780 | $this->db->multi('', []);
|
766 | 781 | }
|
767 | 782 |
|
768 | 783 | /**
|
769 |
| - * @dataProvider driverProvider |
770 |
| - * @expectedException \chillerlan\Database\Drivers\DriverException |
771 |
| - * @expectedExceptionMessage sql error: |
| 784 | + * @dataProvider driverProvider |
772 | 785 | */
|
773 | 786 | public function testMultiSQLError(string $driver, string $env_prefix, bool $skip_on_ci){
|
| 787 | + $this->expectException(DriverException::class); |
| 788 | + $this->expectExceptionMessage('sql error:'); |
| 789 | + |
774 | 790 | $this->dbInstance($driver, $env_prefix, $skip_on_ci);
|
775 | 791 |
|
776 | 792 | $this->db->multi('UPDATE foo bar ???', [[0]]);
|
777 | 793 | }
|
778 | 794 |
|
779 | 795 | /**
|
780 |
| - * @dataProvider driverProvider |
781 |
| - * @expectedException \chillerlan\Database\Drivers\DriverException |
782 |
| - * @expectedExceptionMessage invalid data |
| 796 | + * @dataProvider driverProvider |
783 | 797 | */
|
784 | 798 | public function testMultiInvalidData(string $driver, string $env_prefix, bool $skip_on_ci){
|
| 799 | + $this->expectException(DriverException::class); |
| 800 | + $this->expectExceptionMessage('invalid data'); |
| 801 | + |
785 | 802 | $this->dbInstance($driver, $env_prefix, $skip_on_ci);
|
786 | 803 |
|
787 | 804 | $this->db->multi('UPDATE foo bar ???', []);
|
788 | 805 | }
|
789 | 806 |
|
790 | 807 | /**
|
791 |
| - * @dataProvider driverProvider |
792 |
| - * @expectedException \chillerlan\Database\Drivers\DriverException |
793 |
| - * @expectedExceptionMessage sql error: empty sql |
| 808 | + * @dataProvider driverProvider |
794 | 809 | */
|
795 | 810 | public function testMultiCallbackEmptySQL(string $driver, string $env_prefix, bool $skip_on_ci){
|
| 811 | + $this->expectException(DriverException::class); |
| 812 | + $this->expectExceptionMessage('sql error: empty sql'); |
| 813 | + |
796 | 814 | $this->dbInstance($driver, $env_prefix, $skip_on_ci);
|
797 | 815 |
|
798 | 816 | $this->db->multiCallback('', [], function(){});
|
799 | 817 | }
|
800 | 818 |
|
801 | 819 | /**
|
802 |
| - * @dataProvider driverProvider |
803 |
| - * @expectedException \chillerlan\Database\Drivers\DriverException |
804 |
| - * @expectedExceptionMessage invalid callback |
| 820 | + * @dataProvider driverProvider |
805 | 821 | */
|
806 | 822 | public function testMultiCallbackInvalidCallback(string $driver, string $env_prefix, bool $skip_on_ci){
|
| 823 | + $this->expectException(DriverException::class); |
| 824 | + $this->expectExceptionMessage('invalid callback'); |
| 825 | + |
807 | 826 | $this->dbInstance($driver, $env_prefix, $skip_on_ci);
|
808 | 827 |
|
809 | 828 | $this->db->multiCallback('UPDATE foo bar ???', [[0]], [$this, 'foo']);
|
810 | 829 | }
|
811 | 830 |
|
812 | 831 | /**
|
813 |
| - * @dataProvider driverProvider |
814 |
| - * @expectedException \chillerlan\Database\Drivers\DriverException |
815 |
| - * @expectedExceptionMessage sql error: |
| 832 | + * @dataProvider driverProvider |
816 | 833 | */
|
817 | 834 | public function testMultiCallbackSQLError(string $driver, string $env_prefix, bool $skip_on_ci){
|
| 835 | + $this->expectException(DriverException::class); |
| 836 | + $this->expectExceptionMessage('sql error:'); |
| 837 | + |
818 | 838 | $this->dbInstance($driver, $env_prefix, $skip_on_ci);
|
819 | 839 |
|
820 | 840 | $this->db->multiCallback('UPDATE foo bar ???', [[0]], function($r){ return $r; });
|
821 | 841 | }
|
822 | 842 |
|
823 | 843 | /**
|
824 |
| - * @dataProvider driverProvider |
825 |
| - * @expectedException \chillerlan\Database\Drivers\DriverException |
826 |
| - * @expectedExceptionMessage invalid data |
| 844 | + * @dataProvider driverProvider |
827 | 845 | */
|
828 | 846 | public function testMultiCallbackInvalidData(string $driver, string $env_prefix, bool $skip_on_ci){
|
| 847 | + $this->expectException(DriverException::class); |
| 848 | + $this->expectExceptionMessage('invalid data'); |
| 849 | + |
829 | 850 | $this->dbInstance($driver, $env_prefix, $skip_on_ci);
|
830 | 851 |
|
831 | 852 | $this->db->multiCallback('UPDATE foo bar ???', [], function($r){ return $r; });
|
|
0 commit comments