<commit_before><?php
declare(strict_types=1);
/**
 * This file is part of stubbles.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @package  stubbles\peer
 */
namespace stubbles\peer;
use bovigo\callmap\NewCallable;

use function bovigo\assert\{
    assert,
    assertFalse,
    assertTrue,
    expect,
    predicate\isInstanceOf
};
/**
 * Test for stubbles\peer\Socket.
 *
 * @group  peer
 * @group  socket
 */
class SocketTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @test
     */
    public function createWithEmptyHostThrowsIllegalArgumentException()
    {
        expect(function() { createSocket(''); })
                ->throws(\InvalidArgumentException::class);
    }

    /**
     * @test
     */
    public function createWithNegativePortThrowsIllegalArgumentException()
    {
        expect(function() { createSocket('localhost', -1); })
                ->throws(\InvalidArgumentException::class);
    }

    /**
     * @test
     */
    public function isNotSecureByDefault()
    {
        $socket = createSocket('example.com');
        assertFalse($socket->usesSsl());
    }

    public function securePrefixes(): array
    {
        return [['ssl://'], ['tls://']];
    }

    /**
     * @test
     * @dataProvider  securePrefixes
     */
    public function isSecureWhenCorrectPrefixGiven(string $securePrefix)
    {
        $socket = createSocket('example.com', 443, $securePrefix);
        assertTrue($socket->usesSsl());
    }

    /**
     * @test
     * @since  6.0.0
     */
    public function connectReturnsStream()
    {
        $socket = createSocket('localhost', 80)->openWith(
                NewCallable::of('fsockopen')->mapCall(fopen(__FILE__, 'rb'))
        );
        assert(
                createSocket('localhost', 80)->connect(),
                isInstanceOf(Stream::class)
        );
    }

    /**
     * @test
     * @since  6.0.0<commit_msg>let's use the correct instance<commit_after><?php
declare(strict_types=1);
/**
 * This file is part of stubbles.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @package  stubbles\peer
 */
namespace stubbles\peer;
use bovigo\callmap\NewCallable;

use function bovigo\assert\{
    assert,
    assertFalse,
    assertTrue,
    expect,
    predicate\isInstanceOf
};
/**
 * Test for stubbles\peer\Socket.
 *
 * @group  peer
 * @group  socket
 */
class SocketTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @test
     */
    public function createWithEmptyHostThrowsIllegalArgumentException()
    {
        expect(function() { createSocket(''); })
                ->throws(\InvalidArgumentException::class);
    }

    /**
     * @test
     */
    public function createWithNegativePortThrowsIllegalArgumentException()
    {
        expect(function() { createSocket('localhost', -1); })
                ->throws(\InvalidArgumentException::class);
    }

    /**
     * @test
     */
    public function isNotSecureByDefault()
    {
        $socket = createSocket('example.com');
        assertFalse($socket->usesSsl());
    }

    public function securePrefixes(): array
    {
        return [['ssl://'], ['tls://']];
    }

    /**
     * @test
     * @dataProvider  securePrefixes
     */
    public function isSecureWhenCorrectPrefixGiven(string $securePrefix)
    {
        $socket = createSocket('example.com', 443, $securePrefix);
        assertTrue($socket->usesSsl());
    }

    /**
     * @test
     * @since  6.0.0
     */
    public function connectReturnsStream()
    {
        $socket = createSocket('localhost', 80)->openWith(
                NewCallable::of('fsockopen')->mapCall(fopen(__FILE__, 'rb'))
        );
        assert(
                $socket->connect(),
                isInstanceOf(Stream::class)
        );
    }

    /**
     * @test
     * @since  6.0.0
{'fraction_non_alphanumeric': 0.13506690229739965, 'fraction_numerical': 0.007068921989396617, 'mean_word_length': 2.3238255033557045, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7630876', 'n_tokens_mistral': 1165, 'n_tokens_neox': 1117, 'n_words': 224}