<?php

namespace Kylin\Wechat\Tests;

use Kylin\Wechat\Wechat\WechatManager;

/**
 * WechatManager测试
 */
class WechatManagerTest extends TestCase
{
    /**
     * 测试从容器获取WechatManager实例
     */
    public function testCanGetWechatManagerInstance()
    {
        $manager = $this->app->make('wechat');

        $this->assertInstanceOf(WechatManager::class, $manager);
    }

    /**
     * 测试获取公众号实例
     */
    public function testCanGetOfficialAccountInstance()
    {
        $officialAccount = $this->app->make('wechat')->officialAccount();

        $this->assertInstanceOf(\EasyWeChat\OfficialAccount\Application::class, $officialAccount);
    }

    /**
     * 测试获取小程序实例
     */
    public function testCanGetMiniProgramInstance()
    {
        $miniProgram = $this->app->make('wechat')->miniProgram();

        $this->assertInstanceOf(\EasyWeChat\MiniProgram\Application::class, $miniProgram);
    }

    /**
     * 测试获取指定名称的驱动实例
     */
    public function testCanGetDriverWithName()
    {
        // 添加测试配置
        $this->app['config']->set('wechat.accounts.official_account.test', [
            'app_id' => 'test_app_id_2',
            'secret' => 'test_secret_2',
            'token' => 'test_token_2',
            'aes_key' => 'test_aes_key_2',
            'response_type' => 'array',
        ]);

        $officialAccount = $this->app->make('wechat')->officialAccount('test');

        $this->assertInstanceOf(\EasyWeChat\OfficialAccount\Application::class, $officialAccount);
    }

    /**
     * 测试驱动实例缓存
     */
    public function testDriverInstanceCaching()
    {
        $manager = $this->app->make('wechat');

        $instance1 = $manager->officialAccount();
        $instance2 = $manager->officialAccount();

        $this->assertSame($instance1, $instance2);
    }
}