Make WordPress Core

Changeset 62248


Ignore:
Timestamp:
04/21/2026 12:33:43 PM (3 weeks ago)
Author:
SergeyBiryukov
Message:

Tests: Use assertSame() in WP_AI_Client_Prompt_Builder tests.

This ensures that not only the return values match the expected results, but also that their type is the same.

Going forward, stricter type checking by using assertSame() should generally be preferred to assertEquals() where appropriate, to make the tests more reliable.

Follow-up to [61700].

Props sagardeshmukh.
See #64324.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/ai-client/wpAiClientPromptBuilder.php

    r62101 r62248  
    189189
    190190        $this->assertInstanceOf( RequestOptions::class, $request_options );
    191         $this->assertEquals( 30, $request_options->getTimeout() );
     191        $this->assertSame( 30.0, $request_options->getTimeout() );
    192192    }
    193193
     
    211211
    212212        $this->assertInstanceOf( RequestOptions::class, $request_options );
    213         $this->assertEquals( 45, $request_options->getTimeout() );
     213        $this->assertSame( 45.0, $request_options->getTimeout() );
    214214    }
    215215
     
    402402        $this->assertCount( 1, $messages );
    403403        $this->assertInstanceOf( Message::class, $messages[0] );
    404         $this->assertEquals( 'Hello, world!', $messages[0]->getParts()[0]->getText() );
     404        $this->assertSame( 'Hello, world!', $messages[0]->getParts()[0]->getText() );
    405405    }
    406406
     
    419419        $this->assertCount( 1, $messages );
    420420        $this->assertInstanceOf( Message::class, $messages[0] );
    421         $this->assertEquals( 'Test message', $messages[0]->getParts()[0]->getText() );
     421        $this->assertSame( 'Test message', $messages[0]->getParts()[0]->getText() );
    422422    }
    423423
     
    480480        $this->assertCount( 1, $messages );
    481481        $this->assertInstanceOf( Message::class, $messages[0] );
    482         $this->assertEquals( 'Hello from array', $messages[0]->getParts()[0]->getText() );
     482        $this->assertSame( 'Hello from array', $messages[0]->getParts()[0]->getText() );
    483483    }
    484484
     
    498498
    499499        $this->assertCount( 1, $messages );
    500         $this->assertEquals( 'Some text', $messages[0]->getParts()[0]->getText() );
     500        $this->assertSame( 'Some text', $messages[0]->getParts()[0]->getText() );
    501501    }
    502502
     
    516516        $parts = $messages[0]->getParts();
    517517        $this->assertCount( 2, $parts );
    518         $this->assertEquals( 'Initial text', $parts[0]->getText() );
    519         $this->assertEquals( ' Additional text', $parts[1]->getText() );
     518        $this->assertSame( 'Initial text', $parts[0]->getText() );
     519        $this->assertSame( ' Additional text', $parts[1]->getText() );
    520520    }
    521521
     
    538538        $file = $messages[0]->getParts()[0]->getFile();
    539539        $this->assertInstanceOf( File::class, $file );
    540         $this->assertEquals( 'data:image/png;base64,' . $base64, $file->getDataUri() );
    541         $this->assertEquals( 'image/png', $file->getMimeType() );
     540        $this->assertSame( 'data:image/png;base64,' . $base64, $file->getDataUri() );
     541        $this->assertSame( 'image/png', $file->getMimeType() );
    542542    }
    543543
     
    559559        $file = $messages[0]->getParts()[0]->getFile();
    560560        $this->assertInstanceOf( File::class, $file );
    561         $this->assertEquals( 'https://example.com/image.jpg', $file->getUrl() );
    562         $this->assertEquals( 'image/jpeg', $file->getMimeType() );
     561        $this->assertSame( 'https://example.com/image.jpg', $file->getUrl() );
     562        $this->assertSame( 'image/jpeg', $file->getMimeType() );
    563563    }
    564564
     
    581581        $file = $messages[0]->getParts()[0]->getFile();
    582582        $this->assertInstanceOf( File::class, $file );
    583         $this->assertEquals( 'image/jpeg', $file->getMimeType() );
     583        $this->assertSame( 'image/jpeg', $file->getMimeType() );
    584584    }
    585585
     
    601601        $file = $messages[0]->getParts()[0]->getFile();
    602602        $this->assertInstanceOf( File::class, $file );
    603         $this->assertEquals( 'https://example.com/audio.mp3', $file->getUrl() );
    604         $this->assertEquals( 'audio/mpeg', $file->getMimeType() );
     603        $this->assertSame( 'https://example.com/audio.mp3', $file->getUrl() );
     604        $this->assertSame( 'audio/mpeg', $file->getMimeType() );
    605605    }
    606606
     
    645645        $parts = $messages[0]->getParts();
    646646        $this->assertCount( 3, $parts );
    647         $this->assertEquals( 'Part 1', $parts[0]->getText() );
    648         $this->assertEquals( 'Part 2', $parts[1]->getText() );
    649         $this->assertEquals( 'Part 3', $parts[2]->getText() );
     647        $this->assertSame( 'Part 1', $parts[0]->getText() );
     648        $this->assertSame( 'Part 2', $parts[1]->getText() );
     649        $this->assertSame( 'Part 3', $parts[2]->getText() );
    650650    }
    651651
     
    671671
    672672        $this->assertCount( 3, $messages );
    673         $this->assertEquals( 'User 1', $messages[0]->getParts()[0]->getText() );
    674         $this->assertEquals( 'Model 1', $messages[1]->getParts()[0]->getText() );
    675         $this->assertEquals( 'User 2', $messages[2]->getParts()[0]->getText() );
     673        $this->assertSame( 'User 1', $messages[0]->getParts()[0]->getText() );
     674        $this->assertSame( 'Model 1', $messages[1]->getParts()[0]->getText() );
     675        $this->assertSame( 'User 2', $messages[2]->getParts()[0]->getText() );
    676676    }
    677677
     
    711711        $parts = $messages[0]->getParts();
    712712        $this->assertCount( 3, $parts );
    713         $this->assertEquals( 'Part 1', $parts[0]->getText() );
    714         $this->assertEquals( 'Part 2', $parts[1]->getText() );
    715         $this->assertEquals( 'Part 3', $parts[2]->getText() );
     713        $this->assertSame( 'Part 1', $parts[0]->getText() );
     714        $this->assertSame( 'Part 2', $parts[1]->getText() );
     715        $this->assertSame( 'Part 3', $parts[2]->getText() );
    716716    }
    717717
     
    736736        $parts = $messages[0]->getParts();
    737737        $this->assertCount( 3, $parts );
    738         $this->assertEquals( 'String part', $parts[0]->getText() );
    739         $this->assertEquals( 'Part 1', $parts[1]->getText() );
    740         $this->assertEquals( 'Part 2', $parts[2]->getText() );
     738        $this->assertSame( 'String part', $parts[0]->getText() );
     739        $this->assertSame( 'Part 1', $parts[1]->getText() );
     740        $this->assertSame( 'Part 2', $parts[2]->getText() );
    741741    }
    742742
     
    776776        $config = $this->get_wrapped_prompt_builder_property_value( $builder, 'modelConfig' );
    777777
    778         $this->assertEquals( 'Be helpful', $config->getSystemInstruction() );
    779         $this->assertEquals( 500, $config->getMaxTokens() );
    780         $this->assertEquals( 0.8, $config->getTemperature() );
    781         $this->assertEquals( 0.95, $config->getTopP() );
    782         $this->assertEquals( 50, $config->getTopK() );
    783         $this->assertEquals( 2, $config->getCandidateCount() );
    784         $this->assertEquals( 'application/json', $config->getOutputMimeType() );
     778        $this->assertSame( 'Be helpful', $config->getSystemInstruction() );
     779        $this->assertSame( 500, $config->getMaxTokens() );
     780        $this->assertSame( 0.8, $config->getTemperature() );
     781        $this->assertSame( 0.95, $config->getTopP() );
     782        $this->assertSame( 50, $config->getTopK() );
     783        $this->assertSame( 2, $config->getCandidateCount() );
     784        $this->assertSame( 'application/json', $config->getOutputMimeType() );
    785785    }
    786786
     
    10021002        $merged_config = $this->get_wrapped_prompt_builder_property_value( $builder, 'modelConfig' );
    10031003
    1004         $this->assertEquals( 'Builder instruction', $merged_config->getSystemInstruction() );
    1005         $this->assertEquals( 500, $merged_config->getMaxTokens() );
    1006         $this->assertEquals( 0.5, $merged_config->getTemperature() );
    1007         $this->assertEquals( 0.9, $merged_config->getTopP() );
    1008         $this->assertEquals( 40, $merged_config->getTopK() );
     1004        $this->assertSame( 'Builder instruction', $merged_config->getSystemInstruction() );
     1005        $this->assertSame( 500, $merged_config->getMaxTokens() );
     1006        $this->assertSame( 0.5, $merged_config->getTemperature() );
     1007        $this->assertSame( 0.9, $merged_config->getTopP() );
     1008        $this->assertSame( 40, $merged_config->getTopK() );
    10091009    }
    10101010
     
    10291029        $this->assertArrayHasKey( 'stopSequences', $custom_options );
    10301030        $this->assertIsArray( $custom_options['stopSequences'] );
    1031         $this->assertEquals( array( 'CONFIG_STOP' ), $custom_options['stopSequences'] );
     1031        $this->assertSame( array( 'CONFIG_STOP' ), $custom_options['stopSequences'] );
    10321032        $this->assertArrayHasKey( 'otherOption', $custom_options );
    1033         $this->assertEquals( 'value', $custom_options['otherOption'] );
     1033        $this->assertSame( 'value', $custom_options['otherOption'] );
    10341034
    10351035        $builder->using_stop_sequences( 'STOP' );
     
    10381038        $merged_config = $this->get_wrapped_prompt_builder_property_value( $builder, 'modelConfig' );
    10391039
    1040         $this->assertEquals( array( 'STOP' ), $merged_config->getStopSequences() );
     1040        $this->assertSame( array( 'STOP' ), $merged_config->getStopSequences() );
    10411041
    10421042        $custom_options = $merged_config->getCustomOptions();
    10431043        $this->assertArrayHasKey( 'stopSequences', $custom_options );
    1044         $this->assertEquals( array( 'CONFIG_STOP' ), $custom_options['stopSequences'] );
     1044        $this->assertSame( array( 'CONFIG_STOP' ), $custom_options['stopSequences'] );
    10451045        $this->assertArrayHasKey( 'otherOption', $custom_options );
    1046         $this->assertEquals( 'value', $custom_options['otherOption'] );
     1046        $this->assertSame( 'value', $custom_options['otherOption'] );
    10471047    }
    10481048
     
    10591059
    10601060        $actual_provider = $this->get_wrapped_prompt_builder_property_value( $builder, 'providerIdOrClassName' );
    1061         $this->assertEquals( 'test-provider', $actual_provider );
     1061        $this->assertSame( 'test-provider', $actual_provider );
    10621062    }
    10631063
     
    10761076        $config = $this->get_wrapped_prompt_builder_property_value( $builder, 'modelConfig' );
    10771077
    1078         $this->assertEquals( 'You are a helpful assistant.', $config->getSystemInstruction() );
     1078        $this->assertSame( 'You are a helpful assistant.', $config->getSystemInstruction() );
    10791079    }
    10801080
     
    10931093        $config = $this->get_wrapped_prompt_builder_property_value( $builder, 'modelConfig' );
    10941094
    1095         $this->assertEquals( 1000, $config->getMaxTokens() );
     1095        $this->assertSame( 1000, $config->getMaxTokens() );
    10961096    }
    10971097
     
    11101110        $config = $this->get_wrapped_prompt_builder_property_value( $builder, 'modelConfig' );
    11111111
    1112         $this->assertEquals( 0.7, $config->getTemperature() );
     1112        $this->assertSame( 0.7, $config->getTemperature() );
    11131113    }
    11141114
     
    11271127        $config = $this->get_wrapped_prompt_builder_property_value( $builder, 'modelConfig' );
    11281128
    1129         $this->assertEquals( 0.9, $config->getTopP() );
     1129        $this->assertSame( 0.9, $config->getTopP() );
    11301130    }
    11311131
     
    11441144        $config = $this->get_wrapped_prompt_builder_property_value( $builder, 'modelConfig' );
    11451145
    1146         $this->assertEquals( 40, $config->getTopK() );
     1146        $this->assertSame( 40, $config->getTopK() );
    11471147    }
    11481148
     
    11611161        $config = $this->get_wrapped_prompt_builder_property_value( $builder, 'modelConfig' );
    11621162
    1163         $this->assertEquals( array( 'STOP', 'END', '###' ), $config->getStopSequences() );
     1163        $this->assertSame( array( 'STOP', 'END', '###' ), $config->getStopSequences() );
    11641164    }
    11651165
     
    11781178        $config = $this->get_wrapped_prompt_builder_property_value( $builder, 'modelConfig' );
    11791179
    1180         $this->assertEquals( 3, $config->getCandidateCount() );
     1180        $this->assertSame( 3, $config->getCandidateCount() );
    11811181    }
    11821182
     
    11951195        $config = $this->get_wrapped_prompt_builder_property_value( $builder, 'modelConfig' );
    11961196
    1197         $this->assertEquals( 'application/json', $config->getOutputMimeType() );
     1197        $this->assertSame( 'application/json', $config->getOutputMimeType() );
    11981198    }
    11991199
     
    12191219        $config = $this->get_wrapped_prompt_builder_property_value( $builder, 'modelConfig' );
    12201220
    1221         $this->assertEquals( $schema, $config->getOutputSchema() );
     1221        $this->assertSame( $schema, $config->getOutputSchema() );
    12221222    }
    12231223
     
    12591259        $config = $this->get_wrapped_prompt_builder_property_value( $builder, 'modelConfig' );
    12601260
    1261         $this->assertEquals( 'application/json', $config->getOutputMimeType() );
     1261        $this->assertSame( 'application/json', $config->getOutputMimeType() );
    12621262    }
    12631263
     
    12771277        $config = $this->get_wrapped_prompt_builder_property_value( $builder, 'modelConfig' );
    12781278
    1279         $this->assertEquals( 'application/json', $config->getOutputMimeType() );
    1280         $this->assertEquals( $schema, $config->getOutputSchema() );
     1279        $this->assertSame( 'application/json', $config->getOutputMimeType() );
     1280        $this->assertSame( $schema, $config->getOutputSchema() );
    12811281    }
    12821282
     
    18251825
    18261826        $this->assertCount( 3, $texts );
    1827         $this->assertEquals( 'Text 1', $texts[0] );
    1828         $this->assertEquals( 'Text 2', $texts[1] );
    1829         $this->assertEquals( 'Text 3', $texts[2] );
     1827        $this->assertSame( 'Text 1', $texts[0] );
     1828        $this->assertSame( 'Text 2', $texts[1] );
     1829        $this->assertSame( 'Text 3', $texts[2] );
    18301830
    18311831        /** @var ModelConfig $config */
    18321832        $config = $this->get_wrapped_prompt_builder_property_value( $builder, 'modelConfig' );
    18331833
    1834         $this->assertEquals( 3, $config->getCandidateCount() );
     1834        $this->assertSame( 3, $config->getCandidateCount() );
    18351835    }
    18361836
     
    22562256        $config = $this->get_wrapped_prompt_builder_property_value( $builder, 'modelConfig' );
    22572257
    2258         $this->assertEquals( '16:9', $config->getOutputMediaAspectRatio() );
     2258        $this->assertSame( '16:9', $config->getOutputMediaAspectRatio() );
    22592259    }
    22602260
     
    22732273        $config = $this->get_wrapped_prompt_builder_property_value( $builder, 'modelConfig' );
    22742274
    2275         $this->assertEquals( 'alloy', $config->getOutputSpeechVoice() );
     2275        $this->assertSame( 'alloy', $config->getOutputSpeechVoice() );
    22762276    }
    22772277
     
    22912291        $this->assertNotNull( $declarations );
    22922292        $this->assertCount( 1, $declarations );
    2293         $this->assertEquals( 'wpab__wpaiclienttests__simple', $declarations[0]->getName() );
    2294         $this->assertEquals( 'A simple test ability with no parameters.', $declarations[0]->getDescription() );
     2293        $this->assertSame( 'wpab__wpaiclienttests__simple', $declarations[0]->getName() );
     2294        $this->assertSame( 'A simple test ability with no parameters.', $declarations[0]->getDescription() );
    22952295    }
    22962296
     
    23122312        $this->assertNotNull( $declarations );
    23132313        $this->assertCount( 1, $declarations );
    2314         $this->assertEquals( 'wpab__wpaiclienttests__with-params', $declarations[0]->getName() );
    2315         $this->assertEquals( 'A test ability that accepts parameters.', $declarations[0]->getDescription() );
     2314        $this->assertSame( 'wpab__wpaiclienttests__with-params', $declarations[0]->getName() );
     2315        $this->assertSame( 'A test ability that accepts parameters.', $declarations[0]->getDescription() );
    23162316
    23172317        $params = $declarations[0]->getParameters();
     
    23402340        $this->assertNotNull( $declarations );
    23412341        $this->assertCount( 3, $declarations );
    2342         $this->assertEquals( 'wpab__wpaiclienttests__simple', $declarations[0]->getName() );
    2343         $this->assertEquals( 'wpab__wpaiclienttests__with-params', $declarations[1]->getName() );
    2344         $this->assertEquals( 'wpab__wpaiclienttests__returns-error', $declarations[2]->getName() );
     2342        $this->assertSame( 'wpab__wpaiclienttests__simple', $declarations[0]->getName() );
     2343        $this->assertSame( 'wpab__wpaiclienttests__with-params', $declarations[1]->getName() );
     2344        $this->assertSame( 'wpab__wpaiclienttests__returns-error', $declarations[2]->getName() );
    23452345    }
    23462346
     
    23682368        $this->assertNotNull( $declarations );
    23692369        $this->assertCount( 2, $declarations );
    2370         $this->assertEquals( 'wpab__wpaiclienttests__simple', $declarations[0]->getName() );
    2371         $this->assertEquals( 'wpab__wpaiclienttests__with-params', $declarations[1]->getName() );
     2370        $this->assertSame( 'wpab__wpaiclienttests__simple', $declarations[0]->getName() );
     2371        $this->assertSame( 'wpab__wpaiclienttests__with-params', $declarations[1]->getName() );
    23722372    }
    23732373
     
    24082408        $this->assertNotNull( $declarations );
    24092409        $this->assertCount( 2, $declarations );
    2410         $this->assertEquals( 'wpab__wpaiclienttests__simple', $declarations[0]->getName() );
    2411         $this->assertEquals( 'wpab__wpaiclienttests__with-params', $declarations[1]->getName() );
     2410        $this->assertSame( 'wpab__wpaiclienttests__simple', $declarations[0]->getName() );
     2411        $this->assertSame( 'wpab__wpaiclienttests__with-params', $declarations[1]->getName() );
    24122412    }
    24132413
     
    24272427        $this->assertNotNull( $declarations );
    24282428        $this->assertCount( 1, $declarations );
    2429         $this->assertEquals( 'wpab__wpaiclienttests__hyphen-test', $declarations[0]->getName() );
     2429        $this->assertSame( 'wpab__wpaiclienttests__hyphen-test', $declarations[0]->getName() );
    24302430    }
    24312431
     
    24492449        $this->assertNotNull( $declarations );
    24502450        $this->assertCount( 1, $declarations );
    2451         $this->assertEquals( 'wpab__wpaiclienttests__simple', $declarations[0]->getName() );
     2451        $this->assertSame( 'wpab__wpaiclienttests__simple', $declarations[0]->getName() );
    24522452
    24532453        /** @var ModelConfig $config */
    24542454        $config = $this->get_wrapped_prompt_builder_property_value( $builder, 'modelConfig' );
    24552455
    2456         $this->assertEquals( 'You are a helpful assistant', $config->getSystemInstruction() );
    2457         $this->assertEquals( 500, $config->getMaxTokens() );
     2456        $this->assertSame( 'You are a helpful assistant', $config->getSystemInstruction() );
     2457        $this->assertSame( 500, $config->getMaxTokens() );
    24582458    }
    24592459
Note: See TracChangeset for help on using the changeset viewer.